I'm still in the "wrestling with the language" stage of my Go progress, so forgive me for almost definitely missing something very obvious here.
I'm defining two structs, one containing the other. I make an array of the outer structs, pass it to a function, which calls a method on each of the inner structs, modifying their contents. This change is visible within the function, but when adding the outer structs to an array for returning, the outer function can't see the changes. I've tried throwing pointers in everywhere to little avail - somewhat thankfully, because it looked awful.
package main
import "github.com/davecgh/go-spew/spew"
type inner struct {
ints []int
}
func (i *inner) grow() {
i.ints = append(i.ints, 0)
}
type outer struct {
inner inner
}
func growOs(os []outer) (out []outer) {
for _, o := range os {
o.inner.grow()
out = append(out, o)
}
spew.Dump("----------during")
spew.Dump(out)
return
}
func main() {
os := []outer{
outer{},
outer{},
}
spew.Dump("----------pre")
spew.Dump(os)
growOs(os)
spew.Dump("----------post")
spew.Dump(os)
}