I'm trying to retrieve a value from a YAML string and store it as uint32
using gopkg.in/yaml.v2.
When I try to convert a value foo
as follows, I get an error message that says: panic: interface conversion: interface {} is int, not uint32
. I can't understand the reason why I see the error message, because the value foo
is actually 3
and it's in the range of uint32
.
var myYaml = `
foo: 3
`
type SampleYaml struct {
Foo interface{}
}
func main() {
var sampleYaml SampleYaml
var uint32Val uint32
yaml.Unmarshal([]byte(myYaml), &sampleYaml)
uint32Val = sampleYaml.Foo.(uint32)
fmt.Println(uint32Val)
}
Here's the actual code that I'm struggling with.