fix: resolve Codex review findings — stale comments, constructor patterns

- config.go: comments updated from Cfg/NewEtc to Config/NewConfig
- service.go: comment updated from NewSrv to NewService
- embed.go: comments updated from Emb to Embed
- command.go: panic strings updated from NewSubFunction to NewChildCommandFunction
- fs.go: error ops updated from local.Delete to core.Delete
- core.go: header updated to reflect actual file contents
- contract.go: thin constructors inlined as struct literals (NewConfig, NewService, NewCoreI18n, NewBus)

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-18 09:37:34 +00:00
parent 2525d10515
commit 173067719e
7 changed files with 21 additions and 21 deletions

View file

@ -1259,27 +1259,27 @@ func (c *Command) NewChildCommandFunction(name string, description string, fn an
// if not, panic
t := reflect.TypeOf(fn)
if t.Kind() != reflect.Func {
panic("NewSubFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
panic("NewChildCommandFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
}
// Check the function has 1 input ant it's a struct pointer
fnValue := reflect.ValueOf(fn)
if t.NumIn() != 1 {
panic("NewSubFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
panic("NewChildCommandFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
}
// Check the input is a struct pointer
if t.In(0).Kind() != reflect.Ptr {
panic("NewSubFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
panic("NewChildCommandFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
}
if t.In(0).Elem().Kind() != reflect.Struct {
panic("NewSubFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
panic("NewChildCommandFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
}
// Check only 1 output and it's an error
if t.NumOut() != 1 {
panic("NewSubFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
panic("NewChildCommandFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
}
if t.Out(0) != reflect.TypeOf((*error)(nil)).Elem() {
panic("NewSubFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
panic("NewChildCommandFunction '" + name + "' requires a function with the signature 'func(*struct) error'")
}
flags := reflect.New(t.In(0).Elem())
result.Action(func() error {

View file

@ -37,14 +37,14 @@ func NewConfigVar[T any](val T) ConfigVar[T] {
return ConfigVar[T]{val: val, set: true}
}
// Cfg holds configuration settings and feature flags.
// Config holds configuration settings and feature flags.
type Config struct {
mu sync.RWMutex
settings map[string]any
features map[string]bool
}
// NewEtc creates a new configuration store.
// NewConfig creates a new configuration store.
func NewConfig() *Config {
return &Config{
settings: make(map[string]any),

View file

@ -93,15 +93,15 @@ func New(opts ...Option) (*Core, error) {
c := &Core{
app: app,
fs: defaultFS,
cfg: NewConfig(),
cfg: &Config{settings: make(map[string]any), features: make(map[string]bool)},
err: &ErrPan{},
log: &ErrLog{&ErrOpts{Log: defaultLog}},
cli: NewCoreCli(app),
srv: NewService(),
srv: &Service{Services: make(map[string]any)},
lock: &Lock{},
i18n: NewCoreI18n(),
i18n: &I18n{},
}
c.ipc = NewBus(c)
c.ipc = &Ipc{core: c}
for _, o := range opts {
if err := o(c); err != nil {

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: EUPL-1.2
// Package core is a dependency injection and service lifecycle framework for Go.
// This file defines the Core struct, all exported methods, and all With* options.
// This file defines the Core struct, accessors, and IPC/error wrappers.
package core

View file

@ -2,7 +2,7 @@
// Embedded assets for the Core framework.
//
// Emb provides scoped filesystem access for go:embed and any fs.FS.
// Embed provides scoped filesystem access for go:embed and any fs.FS.
// Also includes build-time asset packing (AST scanner + compressor)
// and template-based directory extraction.
//
@ -319,9 +319,9 @@ func getAllFiles(dir string) ([]string, error) {
return result, err
}
// --- Emb: Scoped Filesystem Mount ---
// --- Embed: Scoped Filesystem Mount ---
// Emb wraps an fs.FS with a basedir for scoped access.
// Embed wraps an fs.FS with a basedir for scoped access.
// All paths are relative to basedir.
type Embed struct {
basedir string
@ -379,7 +379,7 @@ func (s *Embed) ReadString(name string) (string, error) {
return string(data), nil
}
// Sub returns a new Emb anchored at a subdirectory within this mount.
// Sub returns a new Embed anchored at a subdirectory within this mount.
func (s *Embed) Sub(subDir string) (*Embed, error) {
sub, err := fs.Sub(s.fsys, s.path(subDir))
if err != nil {
@ -402,7 +402,7 @@ func (s *Embed) EmbedFS() embed.FS {
return embed.FS{}
}
// BaseDir returns the basedir this Emb is anchored at.
// BaseDir returns the basedir this Embed is anchored at.
func (s *Embed) BaseDir() string {
return s.basedir
}

View file

@ -254,7 +254,7 @@ func (m *Fs) Delete(p string) error {
return err
}
if full == "/" || full == os.Getenv("HOME") {
return E("local.Delete", "refusing to delete protected path: "+full, nil)
return E("core.Delete", "refusing to delete protected path: "+full, nil)
}
return os.Remove(full)
}
@ -266,7 +266,7 @@ func (m *Fs) DeleteAll(p string) error {
return err
}
if full == "/" || full == os.Getenv("HOME") {
return E("local.DeleteAll", "refusing to delete protected path: "+full, nil)
return E("core.DeleteAll", "refusing to delete protected path: "+full, nil)
}
return os.RemoveAll(full)
}

View file

@ -17,7 +17,7 @@ type Service struct {
locked bool
}
// NewSrv creates an empty service registry.
// NewService creates an empty service registry.
func NewService() *Service {
return &Service{
Services: make(map[string]any),