Created
June 5, 2019 12:24
-
-
Save osdrv/fc590efbc59450a9758b5399acff3d5a to your computer and use it in GitHub Desktop.
YAML parser attribute name case insensitivity
This file contains hidden or 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" | |
"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