Reads from file

This commit is contained in:
Mike Farah 2015-09-27 08:20:42 +10:00
parent c00f686a74
commit c4bc70955e
2 changed files with 16 additions and 13 deletions

4
sample.yaml Normal file
View File

@ -0,0 +1,4 @@
a: Easy! as one two three
b:
c: 2
d: [3, 4]

25
yaml.go
View File

@ -4,23 +4,22 @@ import (
"fmt"
"gopkg.in/yaml.v2"
"log"
"io/ioutil"
)
var data = `
a: Easy!
b:
c: 2
d: [3, 4]
`
func main() {
var m interface{}
var raw_data, read_error = ioutil.ReadFile("sample.yaml")
err := yaml.Unmarshal([]byte(data), &m)
if err != nil {
log.Fatalf("error: %v", err)
if read_error != nil {
log.Fatalf("error: %v", read_error)
}
fmt.Println("Hello, 世界")
fmt.Println(m)
var parsed_data interface{}
err := yaml.Unmarshal([]byte(raw_data), &parsed_data)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Println(parsed_data)
}