【发布时间】:2026-01-22 02:15:01
【问题描述】:
我正在尝试使用 Golang 为 Google 数据存储区中的单个属性保存多个值。
我有一个 int64 切片,我希望能够存储和检索它。从文档中我可以看到通过实现 PropertyLoadSaver{} 接口对此提供了支持。但我似乎无法提出正确的实现。
基本上,这就是我想要完成的:
type Post struct {
Title string
UpVotes []int64 `json:"-" xml:"-" datastore:",multiple"`
DownVotes []int64 `json:"-" xml:"-" datastore:",multiple"`
}
c := appengine.NewContext(r)
p := &Post{
Title: "name"
UpVotes: []int64{23, 45, 67, 89, 10}
DownVotes: []int64{90, 87, 65, 43, 21, 123}
}
k := datastore.NewIncompleteKey(c, "Post", nil)
err := datastore.Put(c, k, p)
但没有“数据存储区:无效的实体类型”错误。
【问题讨论】:
标签: google-app-engine go google-cloud-datastore