Last active
October 18, 2024 22:41
-
-
Save ka2n/4457eacdb6c986624eb29cc02fe8d31c to your computer and use it in GitHub Desktop.
Parse yaml with dynamic key name usign go.
This file contains 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 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