Created
July 11, 2018 23:21
-
-
Save locona/131d3bf9dd355330d259c730d5e4b17e to your computer and use it in GitHub Desktop.
[golang] yaml multiple document parse
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 ( | |
"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