Я пытаюсь реализовать две простые структуры следующим образом:
package main
import (
"fmt"
)
type MyBoxItem struct {
Name string
}
type MyBox struct {
Items []MyBoxItem
}
func (box *MyBox) AddItem(item MyBoxItem) []MyBoxItem {
return append(box.Items, item)
}
func main() {
item1 := MyBoxItem{Name: "Test Item 1"}
item2 := MyBoxItem{Name: "Test Item 2"}
items := []MyBoxItem{}
box := MyBox{items}
AddItem(box, item1) // This is where i am stuck
fmt.Println(len(box.Items))
}
Что я делаю неправильно? Я просто хочу вызвать метод addItem в структуре ящика и передать элемент в