Skip to content

Instantly share code, notes, and snippets.

@ka2n
Last active May 2, 2021
Embed
What would you like to do?
Parse yaml with dynamic key name usign go.
package main
import (
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
type Config struct {
Key string `yaml:"key"`
}
func main() {
b, err := ioutil.ReadFile("./settings.yml")
if err != nil {
log.Fatal(err)
}
var cfg map[string]Config
if err := yaml.Unmarshal(b, &cfg); err != nil {
log.Fatal(err)
}
log.Printf("%+v", cfg)
}
development:
key: arg_for_development
production:
key: arg_for_production
env1:
key: arg_for_env1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment