我有一个包装函数mypkg.GetStart周围datastore.GetMulti。包装函数的参数必须与相同appengine.GetMulti。就dst本例而言,我想获得的前两个实体。我的代码当前如下所示,但不起作用。datastore.GetMulti产生错误datastore: dst has invalid type。
mypkg.GetStart
datastore.GetMulti
appengine.GetMulti
dst
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) }
我通过添加Interface()到dstSlice:
Interface()
dstSlice
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.Interface()) }