diff --git a/config.go b/config.go index 395a0f6..cf71d1b 100644 --- a/config.go +++ b/config.go @@ -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() diff --git a/contract.go b/contract.go index b32e7e5..980f248 100644 --- a/contract.go +++ b/contract.go @@ -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, diff --git a/fs.go b/fs.go index 5a28d21..c528308 100644 --- a/fs.go +++ b/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. diff --git a/ipc.go b/ipc.go index 5f22c6f..6f0f99f 100644 --- a/ipc.go +++ b/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