Created
April 16, 2019 04:56
-
-
Save mkulke/3f5ffa64a362e64759437322be33286c to your computer and use it in GitHub Desktop.
go lang yaml unmarshaling
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 ( | |
"fmt" | |
"log" | |
"gopkg.in/yaml.v2" | |
) | |
type Environment struct { | |
Name string | |
Bucket string | |
} | |
type Config struct { | |
Enviroments []Environment `yaml:"environments"` | |
} | |
var data = ` | |
environments: | |
- name: production | |
bucket: prod-bucket | |
bla: blub | |
- name: development | |
bucket: dev-bucket | |
` | |
func main() { | |
c := Config{} | |
err := yaml.Unmarshal([]byte(data), &c) | |
if err != nil { | |
log.Fatalf("error: %v", err) | |
} | |
fmt.Printf("--- c:\n%v\n\n", c) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment