Pergunta

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"
Foi útil?

Solução

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"},
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top