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() | |
} |
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.
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method [recovered]
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
goroutine 20 [running]:
panic(0x807300, 0xc820223610)
/usr/local/go/src/runtime/panic.go:464 +0x3e6
gopkg.in/yaml%2ev2.handleErr(0xc820045f00)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/yaml.go:153 +0xdf
panic(0x807300, 0xc820223610)
/usr/local/go/src/runtime/panic.go:426 +0x4e9
reflect.valueInterface(0x903860, 0xc820226040, 0x1d9, 0x807301, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:919 +0xe7
reflect.Value.Interface(0x903860, 0xc820226040, 0x1d9, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:908 +0x48
gopkg.in/yaml%2ev2.(*encoder).marshal(0xc8201782c0, 0x0, 0x0, 0x903860, 0xc820226040, 0x1d9)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/encode.go:67 +0x89
gopkg.in/yaml%2ev2.(*encoder).structv.func1()
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/encode.go:166 +0x81d
gopkg.in/yaml%2ev2.(*encoder).mappingv(0xc8201782c0, 0x0, 0x0, 0xc8200458c0)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/encode.go:196 +0x181
gopkg.in/yaml%2ev2.(*encoder).structv(0xc8201782c0, 0x0, 0x0, 0x955840, 0xc820226000, 0x199)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/encode.go:184 +0x11b
gopkg.in/yaml%2ev2.(*encoder).marshal(0xc8201782c0, 0x0, 0x0, 0x955840, 0xc820226000, 0x199)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/encode.go:101 +0xa16
gopkg.in/yaml%2ev2.(*encoder).slicev(0xc8201782c0, 0x0, 0x0, 0x916c40, 0xc82010ed80, 0x197)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/encode.go:212 +0x247
gopkg.in/yaml%2ev2.(*encoder).marshal(0xc8201782c0, 0x0, 0x0, 0x916c40, 0xc82010ed80, 0x197)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/encode.go:106 +0x988
gopkg.in/yaml%2ev2.(*encoder).marshal(0xc8201782c0, 0x0, 0x0, 0x91e840, 0xc82010ed80, 0x16)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/encode.go:98 +0x827
gopkg.in/yaml%2ev2.Marshal(0x91e840, 0xc82010ed80, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/eric/Dropbox/go/src/gopkg.in/yaml.v2/yaml.go:142 +0x11e
nearby/rest/lib.Users.Export.func2(0xc820223320, 0xc82010ed80)
/home/eric/Dropbox/go/src/nearby/rest/lib/user.go:153 +0x74
created by nearby/rest/lib.Users.Export
/home/eric/Dropbox/go/src/nearby/rest/lib/user.go:158 +0x45a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Under Go 1.6 go-yaml fails like this:
encoding/json is fine.