diff --git a/pkg/core/contract.go b/pkg/core/contract.go index 8e74b0c..cab7fa0 100644 --- a/pkg/core/contract.go +++ b/pkg/core/contract.go @@ -8,8 +8,6 @@ import ( "context" "embed" "fmt" - "io/fs" - "path/filepath" "reflect" "strings" ) @@ -188,32 +186,6 @@ func WithAssets(efs embed.FS) Option { } } -// WithIO sandboxes filesystem I/O to a root path. -func WithIO(root string) Option { - return func(c *Core) error { - abs, err := filepath.Abs(root) - if err != nil { - return E("core.WithIO", "failed to create IO at "+root, err) - } - if resolved, err := filepath.EvalSymlinks(abs); err == nil { - abs = resolved - } - c.fs = &Fs{root: abs} - return nil - } -} - -// WithMount mounts an fs.FS at a specific subdirectory. -func WithMount(fsys fs.FS, basedir string) Option { - return func(c *Core) error { - sub, err := Mount(fsys, basedir) - if err != nil { - return E("core.WithMount", "failed to mount "+basedir, err) - } - c.emb = sub - return nil - } -} // WithServiceLock prevents service registration after initialisation. func WithServiceLock() Option { diff --git a/pkg/core/core.go b/pkg/core/core.go index a54b6f6..ad5aa4d 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -46,12 +46,10 @@ func (c *Core) Core() *Core { return c } // --- IPC (uppercase aliases) --- -func (c *Core) ACTION(msg Message) error { return c.Action(msg) } -func (c *Core) RegisterAction(handler func(*Core, Message) error) { c.RegisterAction(handler) } -func (c *Core) RegisterActions(handlers ...func(*Core, Message) error) { c.RegisterActions(handlers...) } -func (c *Core) QUERY(q Query) (any, bool, error) { return c.Query(q) } -func (c *Core) QUERYALL(q Query) ([]any, error) { return c.QueryAll(q) } -func (c *Core) PERFORM(t Task) (any, bool, error) { return c.Perform(t) } +func (c *Core) ACTION(msg Message) error { return c.Action(msg) } +func (c *Core) QUERY(q Query) (any, bool, error) { return c.Query(q) } +func (c *Core) QUERYALL(q Query) ([]any, error) { return c.QueryAll(q) } +func (c *Core) PERFORM(t Task) (any, bool, error) { return c.Perform(t) } // --- Error+Log --- diff --git a/pkg/core/task.go b/pkg/core/task.go index cc6e308..5420d8b 100644 --- a/pkg/core/task.go +++ b/pkg/core/task.go @@ -56,6 +56,18 @@ func (c *Core) Perform(t Task) (any, bool, error) { return nil, false, nil } +func (c *Core) RegisterAction(handler func(*Core, Message) error) { + c.ipc.ipcMu.Lock() + c.ipc.ipcHandlers = append(c.ipc.ipcHandlers, handler) + c.ipc.ipcMu.Unlock() +} + +func (c *Core) RegisterActions(handlers ...func(*Core, Message) error) { + c.ipc.ipcMu.Lock() + c.ipc.ipcHandlers = append(c.ipc.ipcHandlers, handlers...) + c.ipc.ipcMu.Unlock() +} + func (c *Core) RegisterTask(handler TaskHandler) { c.ipc.taskMu.Lock() c.ipc.taskHandlers = append(c.ipc.taskHandlers, handler)