Take a look at the following source code:
import "container/list"
type Stream struct {
list list.List
}
func (s Stream) Append(value interface{}) {
log.Println(s.list.Len())
s.list.PushBack(value)
log.Println(s.list.Len())
}
This code will keep on printing 0
and 1
all the time. Am I doing it wrong?
You're copying your Stream and List values in the Append method.
Either make Append
a pointer receiver
func (s *Stream) Append(value interface{}) {
or make Stream.list
a *list.List
type Stream struct {
list *list.List
}