Skip to content

Instantly share code, notes, and snippets.

@osdrv
Created June 5, 2019 12:28
Show Gist options
  • Save osdrv/2387ad1c19c33691e2a808b26d36a39f to your computer and use it in GitHub Desktop.
Save osdrv/2387ad1c19c33691e2a808b26d36a39f to your computer and use it in GitHub Desktop.
YAML.v2 parser attribute name case sensitivity
package main
import (
"fmt"
yaml "gopkg.in/yaml.v2"
)
type Foo struct {
Attr int32 `yaml:"attrFoo"`
}
const data = `
---
bar:
attrFoo: 42
baz:
attrfoo: 84
barbaz:
attrfoo: 456
attrFoo: 122
`
func main() {
var foomap map[string]Foo
err := yaml.Unmarshal([]byte(data), &foomap)
if err != nil {
panic(err.Error())
}
fmt.Printf("foo map: %+v\n", foomap)
}
// Output: foo map: map[bar:{Attr:42} barbaz:{Attr:122} baz:{Attr:0}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment