some code improvements and rearrangements

This commit is contained in:
Helmut Merz 2023-06-03 09:16:24 +02:00
parent 9797c3515a
commit 4119d61c56
7 changed files with 18 additions and 16 deletions

View file

@ -46,8 +46,7 @@ func (ctx *context) ChildContext(cfg Config) Context {
}
func makeCtx(cfg Config, parent Context) *context {
ctx := context{cfg, parent, nil}
return &ctx
return &context{cfg, parent, nil}
}
// top-level application context

View file

@ -46,10 +46,6 @@ func MakeBase(name string, starter common.StartFct) *Base {
}
}
func Setup(cfg common.Config) common.Config {
return cfg
}
// overridable settings
type Settings map[string]string

View file

@ -14,7 +14,10 @@ func Config() common.Config {
Home: ovr(".", HOME),
AppType: "standard",
}
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
cfg.Add(config.Cfg{
Base: b("config", config.Start),
ConfigFormat: "etc",
})
return &cfg
}

View file

@ -6,11 +6,10 @@ import (
"demo/etc"
"git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/config"
)
func main() {
cfg := config.Setup(etc.Config())
cfg := etc.Config()
fmt.Println(cfg.Name())
appCfg := cfg.(*scopes.Cfg)
fmt.Println(appCfg.Home)

View file

@ -27,6 +27,13 @@ func SetUp(tbase *testing.T) *T {
return t
}
func SetUpApp(tbase *testing.T, cfg common.Config) *T {
t := SetUp(tbase)
t.Ctx = common.AppContext(cfg)
cfg.Starter()(t.Ctx)
return t
}
// testing methods
func (t *T) Run(name string, f func(*T)) bool {

View file

@ -14,7 +14,10 @@ func Config() common.Config {
Home: ovr(".", HOME),
AppType: "standard",
}
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
cfg.Add(config.Cfg{
Base: b("config", config.Start),
ConfigFormat: "etc",
})
return &cfg
}

View file

@ -4,17 +4,12 @@ import (
tbase "testing"
"git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/common"
"git.sr.ht/~cco/go-scopes/config"
"git.sr.ht/~cco/go-scopes/testing"
"git.sr.ht/~cco/go-scopes/tests/etc"
)
func TestConfig(tb *tbase.T) {
t := testing.SetUp(tb)
cfg := config.Setup(etc.Config())
t.Ctx = common.AppContext(cfg)
cfg.Starter()(t.Ctx)
t := testing.SetUpApp(tb, etc.Config())
t.Run("config", ConfigTest)
}