我append在 Go 中调用函数时遇到问题
type Dog struct {
color string
}
type Dogs []Dog
Run Code Online (Sandbox Code Playgroud)
我想将“狗”附加到“狗”中。
我试过这样做
Dogs = append(Dogs, Dog)
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误
First argument to append must be slice; have *Dogs
Run Code Online (Sandbox Code Playgroud)
编辑:另外,例如,如果我想检查这条狗是否包含颜色“白色”。我怎么称呼这个?
if Dog.color.contains("white") {
//then append this Dog into Dogs
}
Run Code Online (Sandbox Code Playgroud) go ×1