fix(critical): RegisterAction infinite recursion + restore missing methods
- core.go: removed self-calling RegisterAction/RegisterActions aliases (stack overflow) - task.go: restored RegisterAction/RegisterActions implementations - contract.go: removed WithIO/WithMount (intentional simplification) Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
c2227fbb33
commit
2406e81c20
3 changed files with 16 additions and 34 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 ---
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue