看了针对下面的结构体,map 定义为 : likes := make(map[string] *Person) 那怎么给likes 添加元素呢。
尝试了诸如 likes["a"].Likes = append(likes["a"], code) 或者 likes["a"].Likes = append(likes["a"].Likes, code) 都不可以。 其中code 是一个 string类型的标亮
```go
type Person struct {
Likes []string
}
```
更多评论
type Person struct {
Likes []string
}
p := new(Person)
p.Likes = append(p.Likes, "movie")
logger.Debug("%v", p.Likes)
result: [movie]
#1
type Person struct {
Likes []string
}
p := Person{make([]string, 1)}
p.Likes = append(p.Likes, "movie")
logger.Debug("%v", p.Likes)
p = Person{Likes: make([]string, 1)}
p.Likes = append(p.Likes, "movie")
logger.Debug("%v", p.Likes)
#2