Couldn't find any existing Go
specific answer so creating a new one.
Our datastore consist of following columns/attributes
Name/ID Email UserID UserName
Now, I want to retrieve these values into my Go
struct. Here is what i have written
type UserDetails struct {
NameID string
Email string `datastore:"Email"`
UserID string `datastore:"UserID"`
UserName string `datastore:UserName`
}
Now, when i am fetching this entity (based on kind), I am manually setting the NameID
i.e.,
func (c DataStoreClient) GetUserDetailsByOrg(ctx context.Context, orgName string) ([]*UserDetails, error) {
var userDetails []*UserDetails
q := datastore.NewQuery(userDetailsKind).
Namespace(orgName)
keys, err := c.client.GetAll(ctx, q, &userDetails)
for i, key := range keys {
userDetails[i].NameID = key.Name
}
return userDetails, err
}
Now, the question that i want to ask that is this the correct approach to retrieve Name/ID
or can i retrieve it by specifying datastore:Name/ID
in struct?