سؤال

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"
هل كانت مفيدة؟

المحلول

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"},
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top