【发布时间】:2011-10-26 14:46:09
【问题描述】:
我正在玩弄 GAE、Go 和数据存储。我有以下结构:
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())。
提前致谢,
【问题讨论】:
标签: google-app-engine google-cloud-datastore go