我有:
type Foo struct{
Name string
Hands map[string]string
}
aFoo := Foo{
Name: "Henry"
Hands: ???????
}
我想为" Hands"设置一些值,但我无法正确理解语法。 例如,我想使用如下地图:
"Left":"broken"
"Right":"missing thumb"
答案 0 :(得分:2)
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"},
}