我正在使用GAE,Go和數據存儲。我有以下結構:使用Go更新Google Appengine數據存儲中的實體
type Coinflip struct {
Participants []*datastore.Key
Head string
Tail string
Done bool
}
type Participant struct {
Email string
Seen datastore.Time
}
(對於那些想知道我保存Participants
作爲切掉Key
指針,因爲Go不自動取消引用的實體。)
現在我想找到一個特定的一個Participant
Email
地址與知識Coinflip
相關聯。像這樣(這工作):
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())
如何保存*found
的數據存儲?我顯然需要密鑰,但Participant
結構和Key
之間的耦合非常鬆散。
我不確定如何從這裏開始。我是否還需要從fetchParticipants
呼叫中歸還鑰匙? Java和Python GAE的實現似乎比較簡單一些(只需在對象上調用put()
)。
由於提前,