我最近在发出简单的 datastore.GetAll() 请求时遇到了以前从未见过的错误。我不明白这是什么意思,也找不到任何包含错误消息的文档或 Google 搜索错误消息的任何帮助。
这是我的代码:
type MyUnderlyingStruct struct {
ApplyTo *datastore.Key
ApplyFrom *datastore.Key
Amount float64
LocationKey *datastore.Key
DepartmentKey *datastore.Key
SubjectAreaKey *datastore.Key
}
type MyStruct []MyUnderlyingStruct
//In the case where I get the error someKey is a valid, complete Key value
// of a different kind that what we are querying for and there is actually
// an entity in my datastore that matches this query
func (x *MyStruct) Load(w http.ResponseWriter, r *http.Request, someKey *datastore.Key) (error) {
c := appengine.NewContext(r)
q := datastore.NewQuery("MyUnderlyingStruct_KindName").Order("-Amount")
if someKey != nil { q = q.Filter("ApplyTo=", someKey) }
keys, err := q.GetAll(c,x)
if _, ok := err.(*datastore.ErrFieldMismatch); ok { err = nil }
if err != nil && err != datastore.Done {return err}
return nil
}
返回此错误:
API error 1 (datastore_v3: BAD_REQUEST): The kind is the empty string.
谁能告诉我为什么会出现这个错误,或者它想告诉我什么?
最佳答案
乍一看您的问题(因为我不熟悉 Google 的数据存储 API),在我看来问题是使用 new
关键字进行清零内存初始化的结果。
当使用关键字创建结构时没有为字段分配起始值,默认值为 0。当映射到字符串时,它是“”(空)。 Go 实际上为您抛出了一个非常有用的错误。
正如您所指出的,您使用了 Mykey := new(datastore.Key)
。感谢您的慷慨,这可以作为 future 用户的答案。
关于google-app-engine - Go 中奇怪的数据存储错误, "The kind is the empty string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28220714/