feat: New() constructors for Config, Fs + simplify contract.go init
Config.New() initialises ConfigOptions. Fs.New(root) sets sandbox root. ErrorLog uses Default() fallback — no explicit init needed. contract.go uses constructors instead of struct literals. All tests green. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
94e1f405fc
commit
9c5cc6ea00
4 changed files with 26 additions and 3 deletions
|
|
@ -48,6 +48,15 @@ type Config struct {
|
|||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
// New initialises a Config with empty settings and features.
|
||||
//
|
||||
// cfg := (&core.Config{}).New()
|
||||
func (e *Config) New() *Config {
|
||||
e.ConfigOptions = &ConfigOptions{}
|
||||
e.ConfigOptions.init()
|
||||
return e
|
||||
}
|
||||
|
||||
// Set stores a configuration value by key.
|
||||
func (e *Config) Set(key string, val any) {
|
||||
e.mu.Lock()
|
||||
|
|
|
|||
|
|
@ -93,10 +93,10 @@ func New(opts ...CoreOption) Result {
|
|||
app: &App{},
|
||||
data: &Data{},
|
||||
drive: &Drive{},
|
||||
fs: &Fs{root: "/"},
|
||||
config: &Config{ConfigOptions: &ConfigOptions{}},
|
||||
fs: (&Fs{}).New("/"),
|
||||
config: (&Config{}).New(),
|
||||
error: &ErrorPanic{},
|
||||
log: &ErrorLog{log: Default()},
|
||||
log: &ErrorLog{},
|
||||
lock: &Lock{},
|
||||
ipc: &Ipc{},
|
||||
info: systemInfo,
|
||||
|
|
|
|||
12
fs.go
12
fs.go
|
|
@ -13,6 +13,18 @@ type Fs struct {
|
|||
root string
|
||||
}
|
||||
|
||||
// New initialises an Fs with the given root directory.
|
||||
// Root "/" means unrestricted access. Empty root defaults to "/".
|
||||
//
|
||||
// fs := (&core.Fs{}).New("/")
|
||||
func (m *Fs) New(root string) *Fs {
|
||||
if root == "" {
|
||||
root = "/"
|
||||
}
|
||||
m.root = root
|
||||
return m
|
||||
}
|
||||
|
||||
// path sanitises and returns the full path.
|
||||
// Absolute paths are sandboxed under root (unless root is "/").
|
||||
// Empty root defaults to "/" — the zero value of Fs is usable.
|
||||
|
|
|
|||
2
ipc.go
2
ipc.go
|
|
@ -12,6 +12,8 @@ import (
|
|||
)
|
||||
|
||||
// Ipc holds IPC dispatch data.
|
||||
//
|
||||
// ipc := (&core.Ipc{}).New()
|
||||
type Ipc struct {
|
||||
ipcMu sync.RWMutex
|
||||
ipcHandlers []func(*Core, Message) Result
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue