Skip to content

Instantly share code, notes, and snippets.

@locona
Created July 11, 2018 23:21
Show Gist options
  • Save locona/131d3bf9dd355330d259c730d5e4b17e to your computer and use it in GitHub Desktop.
Save locona/131d3bf9dd355330d259c730d5e4b17e to your computer and use it in GitHub Desktop.
[golang] yaml multiple document parse
package main
import (
"os"
"github.com/k0kubun/pp"
yaml "gopkg.in/yaml.v2"
)
type DNS struct {
Kind string `yaml:"kind"`
Name string `yaml:"name"`
RRDatas interface{} `yaml:"rrdatas"`
TTL int `yaml:"yaml"`
Type string `yaml:"type"`
}
func main() {
// dns := []DNS{}
// b, _ := ioutil.ReadFile("./export.yaml")
r, err := os.Open("./export.yaml")
if err != nil {
panic(err)
}
defer r.Close()
decoder := yaml.NewDecoder(r)
var thing DNS
for decoder.Decode(&thing) == nil {
pp.Println(thing)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment