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

Side by Side Diff: service/datastore/datastore.go

Issue 1867963003: Add PopulateKey method to datastore. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « pre-commit-go.yml ('k') | service/datastore/datastore_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package datastore 5 package datastore
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "io" 9 "io"
10 "io/ioutil" 10 "io/ioutil"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 func (d *datastoreImpl) NewKey(kind, stringID string, intID int64, parent *Key) *Key { 47 func (d *datastoreImpl) NewKey(kind, stringID string, intID int64, parent *Key) *Key {
48 return NewKey(d.aid, d.ns, kind, stringID, intID, parent) 48 return NewKey(d.aid, d.ns, kind, stringID, intID, parent)
49 } 49 }
50 50
51 func (d *datastoreImpl) NewKeyToks(toks []KeyTok) *Key { 51 func (d *datastoreImpl) NewKeyToks(toks []KeyTok) *Key {
52 return NewKeyToks(d.aid, d.ns, toks) 52 return NewKeyToks(d.aid, d.ns, toks)
53 } 53 }
54 54
55 // PopulateKey loads key into obj.
56 //
57 // obj is any object that Interface.Get is able to accept.
58 //
59 // This method will panic if obj is an invalid datastore model. If the key could
60 // not be applied to the object, nothing will happen.
61 func PopulateKey(obj interface{}, key *Key) {
62 pls := getMGS(obj)
63 if !pls.SetMeta("key", key) {
64 lst := key.LastTok()
65 if lst.StringID != "" {
66 pls.SetMeta("id", lst.StringID)
67 } else {
68 pls.SetMeta("id", lst.IntID)
69 }
70 pls.SetMeta("kind", lst.Kind)
71 pls.SetMeta("parent", key.Parent())
72 }
73 }
74
55 func runParseCallback(cbIface interface{}) (isKey, hasErr, hasCursorCB bool, mat multiArgType) { 75 func runParseCallback(cbIface interface{}) (isKey, hasErr, hasCursorCB bool, mat multiArgType) {
56 badSig := func() { 76 badSig := func() {
57 panic(fmt.Errorf( 77 panic(fmt.Errorf(
58 "cb does not match the required callback signature: `%T` != `func(TYPE, [CursorCB]) [error]`", 78 "cb does not match the required callback signature: `%T` != `func(TYPE, [CursorCB]) [error]`",
59 cbIface)) 79 cbIface))
60 } 80 }
61 81
62 if cbIface == nil { 82 if cbIface == nil {
63 badSig() 83 badSig()
64 } 84 }
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 currentDir = filepath.Dir(currentDir) 461 currentDir = filepath.Dir(currentDir)
442 } 462 }
443 } 463 }
444 464
445 func filterStop(err error) error { 465 func filterStop(err error) error {
446 if err == Stop { 466 if err == Stop {
447 err = nil 467 err = nil
448 } 468 }
449 return err 469 return err
450 } 470 }
OLDNEW
« no previous file with comments | « pre-commit-go.yml ('k') | service/datastore/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698