Skip to content

osspkg/go-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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