Domanda

I have:

type Foo struct{
  Name string
  Hands map[string]string
}

aFoo := Foo{
  Name: "Henry"
  Hands: ???????
}

I want to set some values for "Hands", but I cannot get the syntax correct. As an example, I want to use a map like:

"Left":"broken"
"Right":"missing thumb"
È stato utile?

Soluzione

Foo{
  Name: "Henry",
  Hands: make(map[string]string),
}
aFoo.Hands["Left"] = "broken"
// or just

Foo{
  Name: "Henry",
  Hands: map[string]string{"Left": "broken", "Right": "missing thumb"},
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top