Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Unified Diff: go/src/infra/gae/libs/gae/prod/datastore_key.go

Issue 1222903002: Refactor current GAE abstraction library to be free of the SDK* (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: fixes Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+}

Powered by Google App Engine
This is Rietveld 408576698