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

Unified Diff: service/datastore/key.go

Issue 2353063004: Add "MkKeyContext" KeyContext generation function. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « service/datastore/datastore_test.go ('k') | service/datastore/key_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/key.go
diff --git a/service/datastore/key.go b/service/datastore/key.go
index 8359203eb7a879bd476a4fc6d7cbaccd1b010ddb..53b3c933a3c24567a5ca8c88c41a06d8664e731c 100644
--- a/service/datastore/key.go
+++ b/service/datastore/key.go
@@ -59,6 +59,14 @@ type KeyContext struct {
Namespace string
}
+// MkKeyContext is a helper function to create a new KeyContext.
+//
+// It is preferable to field-based struct initialization because, as a function,
+// it has the ability to enforce an exact number of parameters.
+func MkKeyContext(appID, namespace string) KeyContext {
+ return KeyContext{AppID: appID, Namespace: namespace}
+}
+
// Matches returns true iff the AppID and Namespace parameters are the same for
// the two KeyContext instances.
func (kc KeyContext) Matches(o KeyContext) bool {
@@ -102,7 +110,7 @@ func (kc KeyContext) NewKey(kind, stringID string, intID int64, parent *Key) *Ke
//
// elems is pairs of (string, string|int|int32|int64) pairs, which correspond to
// Kind/id pairs. Example:
-// KeyContext{"aid", "namespace"}.MakeKey("Parent", 1, "Child", "id")
+// MkKeyContext("aid", "namespace").MakeKey("Parent", 1, "Child", "id")
//
// Would create the key:
// aid:namespace:/Parent,1/Child,id
@@ -178,10 +186,7 @@ func NewKeyEncoded(encoded string) (ret *Key, err error) {
return
}
- ret.kc = KeyContext{
- AppID: r.GetApp(),
- Namespace: r.GetNameSpace(),
- }
+ ret.kc = MkKeyContext(r.GetApp(), r.GetNameSpace())
ret.toks = make([]KeyTok, len(r.Path.Element))
for i, e := range r.Path.Element {
ret.toks[i] = KeyTok{
« no previous file with comments | « service/datastore/datastore_test.go ('k') | service/datastore/key_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698