rename/reorganize access to overridable settings

This commit is contained in:
Helmut Merz 2023-06-02 10:13:27 +02:00
parent f896adfb8c
commit ca37aead92
4 changed files with 8 additions and 8 deletions

View file

@ -61,12 +61,12 @@ func Setup(cfg Config) Config {
type Settings map[string]string type Settings map[string]string
func (s Settings) Get(key, def string) string { func (s Settings) Use(value, key string) string {
if v, ok := os.LookupEnv("SCOPES_" + strings.ToUpper(key)); ok { if v, ok := os.LookupEnv("SCOPES_" + strings.ToUpper(key)); ok {
return v return v
} }
if v, ok := s[key]; ok { if v, ok := s[key]; ok {
return v return v
} }
return def return value
} }

View file

@ -6,18 +6,19 @@ import (
) )
func Config() config.Config { func Config() config.Config {
ovr := Overrides().Get ovr := Overrides().Use
b := config.MakeBase b := config.MakeBase
cfg := scopes.Cfg{ cfg := scopes.Cfg{
Base: b("dummy", scopes.Start), Base: b("dummy", scopes.Start),
Home: ovr(HOME, "."), Home: ovr(".", HOME),
AppType: "standard", AppType: "standard",
} }
cfg.Add(config.Cfg{b("config", config.Start), "etc"}) cfg.Add(config.Cfg{b("config", config.Start), "etc"})
return &cfg return &cfg
} }
// collect here the names of fields that may be overridden via
// explicit Override() or SCOPES_* environment settings.
const ( const (
NAME = "name"
HOME = "home" HOME = "home"
) )

View file

@ -4,7 +4,6 @@ import "git.sr.ht/~cco/go-scopes/config"
func Overrides() config.Settings { func Overrides() config.Settings {
return config.Settings{ return config.Settings{
NAME: "overridden",
HOME: "/home/scopes/app", HOME: "/home/scopes/app",
} }
} }

View file

@ -6,11 +6,11 @@ import (
) )
func Config() config.Config { func Config() config.Config {
ovr := Overrides().Get ovr := Overrides().Use
b := config.MakeBase b := config.MakeBase
cfg := scopes.Cfg{ cfg := scopes.Cfg{
Base: b("dummy", scopes.Start), Base: b("dummy", scopes.Start),
Home: ovr(HOME, "."), Home: ovr(".", HOME),
AppType: "standard", AppType: "standard",
} }
cfg.Add(config.Cfg{b("config", config.Start), "etc"}) cfg.Add(config.Cfg{b("config", config.Start), "etc"})