Combine yaml and environment config
- Parse yaml
- Parse env
- Watch yaml config file
go get gopkg.in/plimble/goconf.v1
typeSampleAstruct {
Astring// PREFIX_ACamelCasebool// PREFIX_CAMELCASEManualOverride1string`envconfig:"manual_override_1"`// PREFIX_MANUAL_OVERRIDE_1SplitWord1string`split_words:"true"`// SPLIT_WORD1IDstring// PREFIX_IDDefaultValuestring`envconfig:"DEFAULT_VALUE"`// PREFIX_DEFAULT_VALUE
}typeSampleAstruct {
Astring`json:"abc"`// abcCamelCasebool`yaml:"cc"`// ccManualOverride1string// manualoverride1SplitWord1string// splitword1IDstring// idDefaultValuestring// defaultvalue
}typeSamplestruct {
Valuestring
}
varbytes=`value: v1`sample:=&Sample{}
// Parse Order: yaml bytes -> yaml file -> enverr=goconf.Parse(sample,
WithEnv("prefix"),
WithYamlFromBytes(bytes),
WithYaml("path.yml"),
)goconf.WatchYamlFile("path.yml", sample, func() error {
fmt.Println("event on chane")
returnnil
})
// or ignore eventgoconf.WatchYamlFile("path.yml", sample, nil)