Created
May 29, 2018 07:34
-
-
Save locona/610e89ab9039f70b541eacf01439aeb9 to your computer and use it in GitHub Desktop.
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" | |
| "github.com/k0kubun/pp" | |
| yaml "gopkg.in/yaml.v2" | |
| ) | |
| type Data struct { | |
| Components []Component `yaml:"components"` | |
| } | |
| type Component struct { | |
| Service string `yaml:"service"` | |
| Fields []Field `yaml:"fields"` | |
| } | |
| type Field struct { | |
| Key string | |
| Label string | |
| } | |
| func main() { | |
| buf, err := ioutil.ReadFile("sample.yaml") | |
| if err != nil { | |
| panic(err) | |
| } | |
| d := &Data{} | |
| if err := yaml.Unmarshal(buf, d); err != nil { | |
| panic(err) | |
| } | |
| pp.Println(d) | |
| } |
Author
locona
commented
May 29, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment