The struct datastore.Entity looks very useful, and it's how I want to process entities, but I don't see any API the makes use of it. Most of the functions (such as Get) take an interface{}
that only seems to work if it is struct that is precisely structured like the incoming data.
// https://godoc.org/cloud.google.com/go/datastore#Client.Get
ctx := context.Background()
client, err := datastore.NewClient(ctx, "project-id")
if err != nil {
// TODO: Handle error.
}
type Article struct {
Title string
Description string
Body string `datastore:",noindex"`
Author *datastore.Key
PublishedAt time.Time
}
key := datastore.NameKey("Article", "articled1", nil)
article := &Article{}
if err := client.Get(ctx, key, article); err != nil {
// TODO: Handle error.
}
How would I obtain this entity in a generalized way? What if I don't know the structure perfectly? (More specifically, how do I obtain an instance of datastore.Entity
instead?)