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

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

Issue 2048933004: Refactor multiarg, split MGS/PLS. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Rebarse? Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | 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 LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 55 // PopulateKey loads key into obj.
56 // 56 //
57 // obj is any object that Interface.Get is able to accept. 57 // obj is any object that Interface.Get is able to accept.
58 // 58 //
59 // This method will panic if obj is an invalid datastore model. If the key could 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. 60 // not be applied to the object, nothing will happen.
61 func PopulateKey(obj interface{}, key *Key) { 61 func PopulateKey(obj interface{}, key *Key) {
62 » pls := getMGS(obj) 62 » populateKeyMGS(getMGS(obj), key)
63 » if !pls.SetMeta("key", key) { 63 }
64
65 func populateKeyMGS(mgs MetaGetterSetter, key *Key) {
66 » if !mgs.SetMeta("key", key) {
64 lst := key.LastTok() 67 lst := key.LastTok()
65 if lst.StringID != "" { 68 if lst.StringID != "" {
66 » » » pls.SetMeta("id", lst.StringID) 69 » » » mgs.SetMeta("id", lst.StringID)
67 } else { 70 } else {
68 » » » pls.SetMeta("id", lst.IntID) 71 » » » mgs.SetMeta("id", lst.IntID)
69 } 72 }
70 » » pls.SetMeta("kind", lst.Kind) 73 » » mgs.SetMeta("kind", lst.Kind)
71 » » pls.SetMeta("parent", key.Parent()) 74 » » mgs.SetMeta("parent", key.Parent())
72 } 75 }
73 } 76 }
74 77
75 func checkMultiSliceType(v interface{}) error { 78 func checkMultiSliceType(v interface{}) error {
76 if reflect.TypeOf(v).Kind() == reflect.Slice { 79 if reflect.TypeOf(v).Kind() == reflect.Slice {
77 return nil 80 return nil
78 } 81 }
79 return fmt.Errorf("argument must be a slice, not %T", v) 82 return fmt.Errorf("argument must be a slice, not %T", v)
80 83
81 } 84 }
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 currentDir = filepath.Dir(currentDir) 514 currentDir = filepath.Dir(currentDir)
512 } 515 }
513 } 516 }
514 517
515 func filterStop(err error) error { 518 func filterStop(err error) error {
516 if err == Stop { 519 if err == Stop {
517 err = nil 520 err = nil
518 } 521 }
519 return err 522 return err
520 } 523 }
OLDNEW
« no previous file with comments | « no previous file | service/datastore/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698