config: rename items in etc; more flexible Add/AddAction methods
This commit is contained in:
parent
2712f3cb38
commit
c241c8ff73
6 changed files with 22 additions and 26 deletions
|
@ -61,8 +61,9 @@ func (cfg *base) Children() []lib.Config {
|
|||
return cfg.children
|
||||
}
|
||||
|
||||
func (cfg *base) Add(child lib.Config) {
|
||||
cfg.children = append(cfg.children, child)
|
||||
func (cfg *base) Add(c ...lib.Config) lib.Config {
|
||||
cfg.children = append(cfg.children, c...)
|
||||
return cfg
|
||||
}
|
||||
|
||||
// implementation-specific methods and functions
|
||||
|
@ -77,10 +78,10 @@ func (cfg *base) WithMessageHandler(hdlr lib.MessageHandler) *base {
|
|||
return cfg
|
||||
}
|
||||
|
||||
func (cfg *base) AddAction(pattern string, spec lib.ActionSpec) {
|
||||
act := ActionConfig(pattern, nil)
|
||||
act.specs = append(act.specs, spec)
|
||||
func (cfg *base) AddAction(pattern string, specs ...lib.ActionSpec) lib.Config {
|
||||
act := ActionConfig(pattern, specs)
|
||||
cfg.actions = append(cfg.actions, act)
|
||||
return cfg
|
||||
}
|
||||
|
||||
func Base(name string, starter lib.StartProc) *base {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
func Config() lib.Config {
|
||||
ovr := Overrides().Use
|
||||
b := config.Base
|
||||
cfg := app.Cfg{
|
||||
app_c := app.Cfg{
|
||||
BaseCfg: b("dummy", app.Start),
|
||||
Home: ovr(".", HOME),
|
||||
AppType: "standard",
|
||||
|
@ -18,11 +18,11 @@ func Config() lib.Config {
|
|||
Logfile: ovr("log/scopes.log", LOGFILE),
|
||||
},
|
||||
}
|
||||
cfg.Add(config.Cfg{
|
||||
app_c.Add(config.Cfg{
|
||||
BaseCfg: b("config", config.Start),
|
||||
ConfigFormat: "etc",
|
||||
})
|
||||
return &cfg
|
||||
return &app_c
|
||||
}
|
||||
|
||||
// collect here the names of fields that may be overridden via
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"demo/etc"
|
||||
|
||||
"git.sr.ht/~cco/go-scopes"
|
||||
"git.sr.ht/~cco/go-scopes/app"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := etc.Config()
|
||||
fmt.Println(cfg.Name())
|
||||
appCfg := cfg.(*app.Cfg)
|
||||
fmt.Println(appCfg.Home)
|
||||
scopes.RunApp(cfg)
|
||||
scopes.RunApp(etc.Config())
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"git.sr.ht/~cco/go-scopes/lib/message"
|
||||
)
|
||||
|
||||
type BaseSpec = baseSpec
|
||||
|
||||
type baseSpec struct {
|
||||
handler lib.ActionHandler
|
||||
receivers []string
|
||||
|
|
|
@ -23,9 +23,9 @@ type Config interface {
|
|||
Step() StepProc
|
||||
MessageHandler() MessageHandler
|
||||
Actions() []ActionConfig
|
||||
AddAction(string, ActionSpec)
|
||||
AddAction(string, ...ActionSpec) Config
|
||||
Children() []Config
|
||||
Add(Config)
|
||||
Add(...Config) Config
|
||||
}
|
||||
|
||||
type Services map[string]Context
|
||||
|
|
|
@ -14,7 +14,7 @@ func Config() lib.Config {
|
|||
ovr := Overrides().Use
|
||||
b := config.Base
|
||||
|
||||
cfg := app.Cfg{
|
||||
app_c := app.Cfg{
|
||||
BaseCfg: b("testing", testing.Start),
|
||||
Home: ovr(".", HOME),
|
||||
AppType: "standard",
|
||||
|
@ -22,21 +22,21 @@ func Config() lib.Config {
|
|||
Logfile: ovr("log/scopes.log", LOGFILE),
|
||||
},
|
||||
}
|
||||
cfg.AddAction("demo",
|
||||
app_c.AddAction("demo",
|
||||
action.Base(action.Forward,
|
||||
[]string{"test-receiver"}))
|
||||
|
||||
cfg_config := config.Cfg{
|
||||
config_c := config.Cfg{
|
||||
BaseCfg: b("config", config.Start),
|
||||
ConfigFormat: "etc",
|
||||
}
|
||||
cfg.Add(cfg_config)
|
||||
app_c.Add(config_c)
|
||||
|
||||
cfg_test_rcvr := b("test-receiver", core.Start)
|
||||
cfg_test_rcvr.AddAction("demo", action.Base(AH_Receiver, nil))
|
||||
cfg.Add(cfg_test_rcvr)
|
||||
test_rcvr := b("test-receiver", core.Start)
|
||||
test_rcvr.AddAction("demo", action.Base(AH_Receiver, nil))
|
||||
app_c.Add(test_rcvr)
|
||||
|
||||
return &cfg
|
||||
return &app_c
|
||||
}
|
||||
|
||||
// register action handlers from ..._test.go here.
|
||||
|
|
Loading…
Add table
Reference in a new issue