I am toying with GAE, Go and the datastore. I have the following structs:
type Coinflip struct {
Participants []*datastore.Key
Head string
Tail string
Done bool
}
type Participant struct {
Email string
Seen datastore.Time
}
(For those wondering I store Participants
as a slice off Key
pointers because Go doesn't automatically dereferences entities.)
Now I want to find a Participant
with a particular Email
address associated with a know Coinflip
. Like so (this works):
coinflip, _ := find(key_as_string, context)
participants, _ := coinflip.fetchParticipants(context) /* a slice of Participant*/
var found *Participant
for i := 0; i < len(participants) && found == nil; i++ {
if participants[i].Email == r.FormValue("email") {
found = &participants[i]
}
}
(*found).Seen = datastore.SecondsToTime(time.Seconds())
How do I save *found
to the datastore? I need the key apparently but the coupling between the Participant
struct and the Key
is very loose.
I'm unsure how to proceed from here. Do I need to return the keys as well from the fetchParticipants
call? The Java and Python GAE implementation seem quite a bit simpler (just call put()
on the object).
Thanks in advance,