Updating the config through resolver variables.
update config via ENV
@env(key#defaut value)
envs:
home: "@env(HOME#/tmp/home)"
path: "@env(PATH#/usr/local/bin)"
import (
"go.osspkg.com/config"
"go.osspkg.com/config/env"
)
type (
ConfigItem struct {
Home string `yaml:"home"`
Path string `yaml:"path"`
}
Config struct {
Envs testConfigItem `yaml:"envs"`
}
)
func main() {
conf := Config{}
res := config.NewConfigResolve(
env.New(), // env resolver
)
res.OpenFile("./config.yaml") // open config file
res.Build() // prepare config with resolvers
res.Decode(&conf) // decoding config
fmt.Println(conf.Envs.Home)
fmt.Println(conf.Envs.Path)
}