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 { func makeCtx(cfg Config, parent Context) *context {
ctx := context{cfg, parent, nil} return &context{cfg, parent, nil}
return &ctx
} }
// top-level application context // 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 // overridable settings
type Settings map[string]string type Settings map[string]string

View file

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

View file

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

View file

@ -27,6 +27,13 @@ func SetUp(tbase *testing.T) *T {
return 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 // testing methods
func (t *T) Run(name string, f func(*T)) bool { func (t *T) Run(name string, f func(*T)) bool {

View file

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

View file

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