Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 773 Bytes

README.md

File metadata and controls

49 lines (38 loc) · 773 Bytes

Config Resolver

Updating the config through resolver variables.

Config example

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)
}