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