mirror of
https://github.com/syntrex-lab/gomcp.git
synced 2026-04-27 21:36:21 +02:00
initial: Syntrex extraction from sentinel-community (615 files)
This commit is contained in:
commit
2c50c993b1
175 changed files with 32396 additions and 0 deletions
52
internal/application/contextengine/config.go
Normal file
52
internal/application/contextengine/config.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package contextengine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
ctxdomain "github.com/sentinel-community/gomcp/internal/domain/context"
|
||||
)
|
||||
|
||||
// LoadConfig loads engine configuration from a JSON file.
|
||||
// If the file does not exist, returns DefaultEngineConfig.
|
||||
// If the file exists but is invalid, returns an error.
|
||||
func LoadConfig(path string) (ctxdomain.EngineConfig, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return ctxdomain.DefaultEngineConfig(), nil
|
||||
}
|
||||
return ctxdomain.EngineConfig{}, err
|
||||
}
|
||||
|
||||
var cfg ctxdomain.EngineConfig
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
return ctxdomain.EngineConfig{}, err
|
||||
}
|
||||
|
||||
// Build skip set from deserialized SkipTools slice.
|
||||
cfg.BuildSkipSet()
|
||||
|
||||
// If skip_tools was omitted in JSON, use defaults.
|
||||
if cfg.SkipTools == nil {
|
||||
cfg.SkipTools = ctxdomain.DefaultSkipTools()
|
||||
cfg.BuildSkipSet()
|
||||
}
|
||||
|
||||
if err := cfg.Validate(); err != nil {
|
||||
return ctxdomain.EngineConfig{}, err
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
// SaveDefaultConfig writes the default configuration to a JSON file.
|
||||
// Useful for bootstrapping .rlm/context.json.
|
||||
func SaveDefaultConfig(path string) error {
|
||||
cfg := ctxdomain.DefaultEngineConfig()
|
||||
data, err := json.MarshalIndent(cfg, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, data, 0o644)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue