Chromium Code Reviews| Index: go/src/infra/gae/libs/gae/helper/shell_key.go |
| diff --git a/go/src/infra/gae/libs/gae/helper/shell_key.go b/go/src/infra/gae/libs/gae/helper/shell_key.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..001e9bde8c8120f5d2d00c4e247e77ccc8ba9694 |
| --- /dev/null |
| +++ b/go/src/infra/gae/libs/gae/helper/shell_key.go |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package helper |
| + |
| +import ( |
| + "infra/gae/libs/gae" |
| +) |
| + |
| +type shellDSKey struct { |
|
Vadim Sh.
2015/07/13 21:17:12
what does "shell" stand for?
iannucci
2015/07/13 22:39:52
it's.. not a very good name. I'll change it. Made
|
| + appID string |
| + namespace string |
| + toks []gae.DSKeyTok |
| +} |
| + |
| +var _ gae.DSKey = (*shellDSKey)(nil) |
| + |
| +// NewDSKeyToks creates a a reference implementation of gae.DSKey. It is the |
| +// DSKey implementation returned from the various DSPropertyMap serialization |
| +// routines, as well as the native key implementation for the in-memory |
| +// implementation of gae. |
| +func NewDSKeyToks(appID, ns string, toks []gae.DSKeyTok) gae.DSKey { |
| + newToks := make([]gae.DSKeyTok, len(toks)) |
| + copy(newToks, toks) |
|
Vadim Sh.
2015/07/13 21:17:12
nit: newToks := append(nil, toks...)? :) It's prob
iannucci
2015/07/13 22:39:52
I guess I'm just paranoid of re-using the slice be
|
| + return &shellDSKey{appID, ns, newToks} |
| +} |
| + |
| +// NewDSKey is a wrapper around NewDSKeyToks which has an interface similar |
| +// to NewKey in the SDK. |
| +func NewDSKey(appID, ns, kind, stringID string, intID int64, parent gae.DSKey) gae.DSKey { |
| + _, _, toks := DSKeySplit(parent) |
| + newToks := make([]gae.DSKeyTok, len(toks)) |
| + copy(newToks, toks) |
| + newToks = append(newToks, gae.DSKeyTok{Kind: kind, StringID: stringID, IntID: intID}) |
| + return &shellDSKey{appID, ns, newToks} |
| +} |
| + |
| +func (k *shellDSKey) lastTok() (ret gae.DSKeyTok) { |
| + if len(k.toks) > 0 { |
| + ret = k.toks[len(k.toks)-1] |
| + } |
| + return |
| +} |
| + |
| +func (k *shellDSKey) AppID() string { return k.appID } |
| +func (k *shellDSKey) Namespace() string { return k.namespace } |
| +func (k *shellDSKey) Kind() string { return k.lastTok().Kind } |
| +func (k *shellDSKey) StringID() string { return k.lastTok().StringID } |
| +func (k *shellDSKey) IntID() int64 { return k.lastTok().IntID } |
| +func (k *shellDSKey) String() string { return DSKeyString(k) } |
| + |
| +func (k *shellDSKey) Parent() gae.DSKey { |
| + if len(k.toks) <= 1 { |
| + return nil |
| + } |
| + return NewDSKeyToks(k.appID, k.namespace, k.toks[:len(k.toks)-1]) |
| +} |