Skip to content

Instantly share code, notes, and snippets.

@osdrv
Created June 5, 2019 12:24
Show Gist options
  • Save osdrv/fc590efbc59450a9758b5399acff3d5a to your computer and use it in GitHub Desktop.
Save osdrv/fc590efbc59450a9758b5399acff3d5a to your computer and use it in GitHub Desktop.
YAML parser attribute name case insensitivity
package main
import (
"fmt"
"github.com/ghodss/yaml"
)
type Foo struct {
Attr int32 `json:"attrFoo"`
}
const data = `
---
bar:
attrFoo: 42
baz:
attrfoo: 84
barbaz:
attrfoo: 456
attrFoo: 123
`
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:456} baz:{Attr:84}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment