-
-
Save synsa/463cf6fb5aa88edcbc4bb31f99ca720d to your computer and use it in GitHub Desktop.
Parse yaml with dynamic key name usign go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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