Hmm... This is the most common mistake that people make when appending to slices in Go. You must assign the result back to slice.
func (box *MyBox) AddItem(item MyBoxItem) []MyBoxItem {
box.Items = append(box.Items, item)
return box.Items
}
Also, you have defined AddItem
for *MyBox
type, so call this method as box.AddItem(item1)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…