golang append issue inside a for loop [duplicate]
问题 This question already has answers here : Range references instead values (3 answers) Using Pointers in a for loop (2 answers) Closed 9 months ago . Problem: append inside Users() for loop below adds the last item in users 3x into userRxs []*UserResolver Expectation: append should add each item inside users into userRxs []*UserResolver // Users return all users from Db func (r *RootResolver) Users() ([]*UserResolver, error) { var userRxs []*UserResolver users := r.Db.Users() for _, u := range