The following go code (shared: link) should insert two positions in an order (both order and position are structs:
package main
import "fmt"
type orderPosition struct{
art string
qty string
}
type order struct{
posList []orderPosition
}
func main() {
o := new(order)
o.loadPos()
fmt.Printf("# pos: %d
",len(o.posList))
}
func (o order) loadPos() {
o.posList = append(o.posList, orderPosition {art: "art 1", qty: "2 pc"})
o.posList = append(o.posList, orderPosition {art: "art 2", qty: "7 pc"})
fmt.Printf("# pos: %d
",len(o.posList))
}
The output is:
# pos: 2
# pos: 0
The method loadPos fills the positions in the order. But as soon as the method is left the list of positions is lost.
Why is the array loosing its content?
Any help would be greatly appreciated.