Skip to content

Instantly share code, notes, and snippets.

@mkulke
Created April 16, 2019 04:56
Show Gist options
  • Save mkulke/3f5ffa64a362e64759437322be33286c to your computer and use it in GitHub Desktop.
Save mkulke/3f5ffa64a362e64759437322be33286c to your computer and use it in GitHub Desktop.
go lang yaml unmarshaling
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