本文整理汇总了Golang中google/golang.org/appengine/datastore.Key.Namespace方法的典型用法代码示例。如果您正苦于以下问题:Golang Key.Namespace方法的具体用法?Golang Key.Namespace怎么用?Golang Key.Namespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google/golang.org/appengine/datastore.Key
的用法示例。
在下文中一共展示了Key.Namespace方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ktoi
func ktoi(key *datastore.Key) id {
return id{
kind: key.Kind(),
stringID: key.StringID(),
intID: key.IntID(),
appID: key.AppID(),
namespace: key.Namespace(),
}
}
示例2: buildKey
func buildKey(req *wcg.Request, key *datastore.Key) *datastore.Key {
kind := entities.FindKind(key.Kind(), key.Namespace())
if kind == nil {
return nil
}
if key.Parent() != nil {
return kind.NewKey(req, key.StringID(), buildKey(req, key.Parent()))
}
return kind.NewKey(req, key.StringID(), nil)
}
示例3: buildDatastoreKey
func buildDatastoreKey(key *datastore.Key) (map[string]bigquery.JsonValue, error) {
if key == nil {
return map[string]bigquery.JsonValue{
"namespace": "",
"app": "",
"path": "",
"kind": "",
"name": "",
"id": 0,
}, nil
}
var workKey = key
var keys []*datastore.Key
keys = append(keys, key)
for {
if workKey.Parent() == nil {
break
}
keys = append(keys, workKey.Parent())
workKey = workKey.Parent()
}
var buf bytes.Buffer
for i := len(keys) - 1; i >= 0; i-- {
if buf.Len() > 0 {
_, err := buf.WriteString(", ")
if err != nil {
return map[string]bigquery.JsonValue{}, nil
}
}
key := keys[i]
if len(key.StringID()) < 1 {
_, err := buf.WriteString(fmt.Sprintf(`"%s", "%s"`, keys[i].Kind(), keys[i].IntID()))
if err != nil {
return map[string]bigquery.JsonValue{}, nil
}
} else {
_, err := buf.WriteString(fmt.Sprintf(`"%s", "%s"`, keys[i].Kind(), keys[i].StringID()))
if err != nil {
return map[string]bigquery.JsonValue{}, nil
}
}
}
return map[string]bigquery.JsonValue{
"namespace": key.Namespace(),
"app": key.AppID(),
"path": buf.String(),
"kind": key.Kind(),
"name": key.StringID(),
"id": key.IntID(),
}, nil
}
示例4: Next
// Next processes the next item
func (x *example5) Next(c context.Context, counters mapper.Counters, key *datastore.Key) error {
photo := x.photo
photo.ID = key.IntID()
out := &photoOutput{
Photo: photo,
Namespace: key.Namespace(),
}
x.encoder.Encode(out)
return nil
}
示例5: dsR2F
// dsR2F (DS real-to-fake) converts an SDK Key to a ds.Key
func dsR2F(k *datastore.Key) *ds.Key {
if k == nil {
return nil
}
aid := k.AppID()
ns := k.Namespace()
count := 0
for nk := k; nk != nil; nk = nk.Parent() {
count++
}
toks := make([]ds.KeyTok, count)
for ; k != nil; k = k.Parent() {
count--
toks[count].Kind = k.Kind()
toks[count].StringID = k.StringID()
toks[count].IntID = k.IntID()
}
return ds.NewKeyToks(aid, ns, toks)
}