I am newbie in Golang, and I get stuck with setting value of variable from anonymous function (another scope). Now I am using goquery.
For example I've following:
models := []model.User{}
doc.Find(".ff").Each(func(i int, s *goquery.Selection) {
//...
models := append(models, model.User{})
})
And this does not work. How can I append new model to models?
:=
declares and initializes a new variable, while =
assigns to an existing variable.
So change your code to
models = append(models, model.User{})