Index: go/src/infra/gae/libs/gae/prod/datastore_key.go |
diff --git a/go/src/infra/gae/libs/gae/prod/datastore_key.go b/go/src/infra/gae/libs/gae/prod/datastore_key.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..03a39780f869cc7fdb7db7cd41ff6083707214b8 |
--- /dev/null |
+++ b/go/src/infra/gae/libs/gae/prod/datastore_key.go |
@@ -0,0 +1,56 @@ |
+// 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 prod |
+ |
+import ( |
+ "infra/gae/libs/gae" |
+ "infra/gae/libs/gae/helper" |
+ |
+ "google.golang.org/appengine/datastore" |
+) |
+ |
+type dsKeyImpl struct { |
Vadim Sh.
2015/07/14 00:12:37
any reason it can't be
type dsKeyImpl *datastore.
iannucci
2015/07/14 01:07:46
Note that it's all bare-struct receivers below, so
|
+ *datastore.Key |
+} |
+ |
+var _ gae.DSKey = dsKeyImpl{} |
+ |
+func (k dsKeyImpl) Equal(other gae.DSKey) bool { return k.Key.Equal(f2r(other)) } |
+func (k dsKeyImpl) Parent() gae.DSKey { return &dsKeyImpl{k.Key.Parent()} } |
Vadim Sh.
2015/07/14 00:12:37
f2r(k.Key.Parent())?
iannucci
2015/07/14 01:07:46
r2f, but yes
|
+func (k dsKeyImpl) Root() gae.DSKey { return helper.DSKeyRoot(k) } |
+func (k dsKeyImpl) Valid(ns string, allowSpecial bool) bool { |
+ return helper.DSKeyValid(k, ns, allowSpecial) |
+} |
+ |
+func r2f(k *datastore.Key) gae.DSKey { |
+ return &dsKeyImpl{k} |
+} |
+ |
+func r2fe(k *datastore.Key, err error) (gae.DSKey, error) { |
+ if err != nil { |
Vadim Sh.
2015/07/14 00:12:37
huh?
iannucci
2015/07/14 01:07:46
it's for wrapping methods which return (*datastore
|
+ return nil, err |
+ } |
+ return r2f(k), nil |
+} |
+ |
+func f2r(k gae.DSKey) *datastore.Key { |
+ return k.(dsKeyImpl).Key |
+} |
+ |
+func mr2f(ks []*datastore.Key) []gae.DSKey { |
Vadim Sh.
2015/07/14 00:12:37
these are very cryptic names :)
iannucci
2015/07/14 01:07:46
yeah, added comments
|
+ ret := make([]gae.DSKey, len(ks)) |
+ for i, k := range ks { |
+ ret[i] = r2f(k) |
+ } |
+ return ret |
+} |
+ |
+func mf2r(ks []gae.DSKey) []*datastore.Key { |
+ ret := make([]*datastore.Key, len(ks)) |
+ for i, k := range ks { |
+ ret[i] = f2r(k) |
+ } |
+ return ret |
+} |