Wilbert
Wilbert

Reputation: 7399

Golang yaml.v2 struct with a map[string]string unmarshalling fails

Im am using the gopkg.in/yaml.v2 package and I'm trying to unmarshal a yaml file like this:

Sizes: 
  A: small
  B: small
  C: medium

I created a go struct like this:

type sizesByType struct {
    Map map[string]string `yaml: "Sizes"`
}

but unmarshaling it with yaml.v2 gives me an empty map.

What am I doing wrong?

Upvotes: 3

Views: 3088

Answers (1)

Alexander Kohler
Alexander Kohler

Reputation: 1967

Remove the space in your struct tag:

type sizesByType struct {
    Map map[string]string `yaml:"Sizes"`
}

Upvotes: 3

Related Questions