Created
March 17, 2016 20:30
-
-
Save mjs/0819ddeb4f5ea93f0889 to your computer and use it in GitHub Desktop.
Demo of go-yaml issue under Go 1.6
This file contains 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 ( | |
"fmt" | |
// Swap these 2 for comparison. Under Go 1.6 the program works | |
// with json but not yaml. | |
"gopkg.in/yaml.v2" | |
// yaml "encoding/json" | |
) | |
type bar struct { | |
N int | |
} | |
type Foo struct { | |
S string | |
bar | |
} | |
func (f *Foo) Dump() { | |
fmt.Printf("S: %s; N=%d\n", f.S, f.N) | |
} | |
func main() { | |
x := Foo{S: "qux"} | |
x.N = 99 | |
x.Dump() | |
bytes, err := yaml.Marshal(x) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("\nmarshalled:\n%s\n\n", string(bytes)) | |
var y Foo | |
err = yaml.Unmarshal(bytes, &y) | |
if err != nil { | |
panic(err) | |
} | |
y.Dump() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting the same problem. Used to work with go 1.5
I now use https://github.com/ghodss/yaml .. No more problem.. No change in my code.