本文整理汇总了Golang中github.com/luci/gae/service/datastore.Key.Valid方法的典型用法代码示例。如果您正苦于以下问题:Golang Key.Valid方法的具体用法?Golang Key.Valid怎么用?Golang Key.Valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/luci/gae/service/datastore.Key
的用法示例。
在下文中一共展示了Key.Valid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Ancestor
func (q *queryImpl) Ancestor(k ds.Key) ds.Query {
return q.checkMutateClone(
func() error {
if k == nil {
// SDK has an explicit nil-check
return errors.New("datastore: nil query ancestor")
}
if k.Namespace() != q.ns {
return fmt.Errorf("bad namespace: %q (expected %q)", k.Namespace(), q.ns)
}
if !k.Valid(false, globalAppID, q.ns) {
// technically the SDK implementation does a Weird Thing (tm) if both the
// stringID and intID are set on a key; it only serializes the stringID in
// the proto. This means that if you set the Ancestor to an invalid key,
// you'll never actually hear about it. Instead of doing that insanity, we
// just swap to an error here.
return ds.ErrInvalidKey
}
if q.eqFilters["__ancestor__"] != nil {
return errors.New("cannot have more than one ancestor")
}
return nil
},
func(q *queryImpl) {
q.addEqFilt("__ancestor__", ds.MkProperty(k))
})
}