本文整理匯總了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))
})
}