I have a function that basically looks like this:
func (db *datastoreDB) GetAllUsers(ctx context.Context) (*[]User, error) {
query := datastore.NewQuery("User")
var users []User
_, err := db.client.GetAll(ctx, query, &users)
return &users, nil
}
with the struct:
type User struct {
username string
password []byte
}
Now, if I try to call
users, err := models.DB.GetAllUsers(ctx)
log.Println(users)
then it will only print 1 user, even though there are many..
I tried to Print using users[0], users[1] but that returned errors, also tried with *users[1], &users[1], and for i, _ range users { log.Println(users[i]) }
Haven't quite been able to understand when/how to use * and & even though I read many online tutorials, so often just do trail and error.. I doubt there is anything wrong with my datastore GetAll function, so I assume I just fail to properly access/return the struct slice but feel like I tried everything..