【发布时间】:2014-05-18 02:20:21
【问题描述】:
我在datastore.GetMulti 周围有一个包装函数mypkg.GetStart。包装函数的参数必须与appengine.GetMulti 相同。为了这个例子,我想得到dst 的前两个实体。我的代码目前如下所示,但不起作用。 datastore.GetMulti 产生错误datastore: dst has invalid type。
type myEntity struct {
Val Int
}
keys := []*datastore.Key{keyOne, keyTwo, keyThree}
entities := make([]myEntity, 3)
mypkg.GetStart(c, keys, enities)
我的mypkg.GetStart代码如下:
func GetStart(c appengine.Context, keys []*datastore.Key, dst interface{}) error{
v := reflect.ValueOf(dst)
dstSlice := v.Slice(0, 2)
return datastore.GetMulti(c, keys, dstSlice)
}
我怎样才能做到这一点?请注意,这是How to sub slice an interface{} that is a slice?
的后续问题【问题讨论】:
标签: google-app-engine go