I am writing a go
application in app engine
that connects and returns some info from datastore
entities. I'm having an issue where client.Get
is working with a predefined struct but client.GetAll
is throwing a type mismatch (or vice versa).
I am using the following struct with both:
type myStruct struct {
ID int64
Field1 string
Field2 string
Release_Date time.Time
}
This works when Release_Date
is defined as time.Time
(fails if int
):
k := db.datastoreKey(id)
myStruct := &myStruct{}
if err := db.client.Get(ctx, k, myStruct ); err != nil {
return nil, fmt.Errorf("datastore: %v", err)
}
func (db *datastoreDB) datastoreKey(id int64) *datastore.Key {
return datastore.IDKey("myEntityType", id, nil)
}
This fails when Release_Date
is defined as time.Time
(works if int
):
var myStructs []*myStruct
q := datastore.NewQuery("myEntityType").
Project("field1", "field2", "release_date").
Order("field1")
keys, err := db.client.GetAll(ctx, q, &myStructs)
if err != nil {
return nil, fmt.Errorf("datastore: %v", err)
}
The error:
datastore: cannot load field "release_date" into a "myStruct": type mismatch: int versus time.Time
(or vice versa when I swap the Release_Date
definition).
Any ideas what is wrong or is this a bug?
Additional info:
I've looked at the entity dashboard and there it lists the data type as Data/Time
and when I retrieve the entity with Get
it loads fine into the struct and I can use the object in my code.
I have no idea why this isn't working.