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

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

Issue 1516173002: Fix error message from KeyForObj when passing an invalid struct. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: remove accidental extra test Created 5 years 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
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 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // - err is an error associated with putting this entity. 45 // - err is an error associated with putting this entity.
46 type PutMultiCB func(key *Key, err error) 46 type PutMultiCB func(key *Key, err error)
47 47
48 // DeleteMultiCB is the callback signature provided to RawInterface.DeleteMulti 48 // DeleteMultiCB is the callback signature provided to RawInterface.DeleteMulti
49 // 49 //
50 // - err is an error associated with deleting this entity. 50 // - err is an error associated with deleting this entity.
51 type DeleteMultiCB func(err error) 51 type DeleteMultiCB func(err error)
52 52
53 type nullMetaGetterType struct{} 53 type nullMetaGetterType struct{}
54 54
55 func (nullMetaGetterType) GetMeta(string) (interface{}, error) { return nil, ErrMetaFieldUnset } 55 func (nullMetaGetterType) GetMeta(string) (interface{}, bool) { return nil, fals e }
56 func (nullMetaGetterType) GetMetaDefault(_ string, dflt interface{}) interface{} { return dflt }
57 56
58 var nullMetaGetter MetaGetter = nullMetaGetterType{} 57 var nullMetaGetter MetaGetter = nullMetaGetterType{}
59 58
60 // MultiMetaGetter is a carrier for metadata, used with RawInterface.GetMulti 59 // MultiMetaGetter is a carrier for metadata, used with RawInterface.GetMulti
61 // 60 //
62 // It's OK to default-construct this. GetMeta will just return 61 // It's OK to default-construct this. GetMeta will just return
63 // (nil, ErrMetaFieldUnset) for every index. 62 // (nil, ErrMetaFieldUnset) for every index.
64 type MultiMetaGetter []MetaGetter 63 type MultiMetaGetter []MetaGetter
65 64
66 // NewMultiMetaGetter returns a new MultiMetaGetter object. data may be nil. 65 // NewMultiMetaGetter returns a new MultiMetaGetter object. data may be nil.
67 func NewMultiMetaGetter(data []PropertyMap) MultiMetaGetter { 66 func NewMultiMetaGetter(data []PropertyMap) MultiMetaGetter {
68 if len(data) == 0 { 67 if len(data) == 0 {
69 return nil 68 return nil
70 } 69 }
71 inner := make(MultiMetaGetter, len(data)) 70 inner := make(MultiMetaGetter, len(data))
72 for i, pm := range data { 71 for i, pm := range data {
73 inner[i] = pm 72 inner[i] = pm
74 } 73 }
75 return inner 74 return inner
76 } 75 }
77 76
78 // GetMeta is like PropertyLoadSaver.GetMeta, but it also takes an index 77 // GetMeta is like PropertyLoadSaver.GetMeta, but it also takes an index
79 // indicating which slot you want metadata for. If idx isn't there, this 78 // indicating which slot you want metadata for. If idx isn't there, this
80 // returns (nil, ErrMetaFieldUnset). 79 // returns (nil, ErrMetaFieldUnset).
81 func (m MultiMetaGetter) GetMeta(idx int, key string) (interface{}, error) { 80 func (m MultiMetaGetter) GetMeta(idx int, key string) (interface{}, bool) {
82 return m.GetSingle(idx).GetMeta(key) 81 return m.GetSingle(idx).GetMeta(key)
83 } 82 }
84 83
85 // GetMetaDefault is like PropertyLoadSaver.GetMetaDefault, but it also takes an
86 // index indicating which slot you want metadata for. If idx isn't there, this
87 // returns dflt.
88 func (m MultiMetaGetter) GetMetaDefault(idx int, key string, dflt interface{}) i nterface{} {
89 return m.GetSingle(idx).GetMetaDefault(key, dflt)
90 }
91
92 // GetSingle gets a single MetaGetter at the specified index. 84 // GetSingle gets a single MetaGetter at the specified index.
93 func (m MultiMetaGetter) GetSingle(idx int) MetaGetter { 85 func (m MultiMetaGetter) GetSingle(idx int) MetaGetter {
94 if idx >= len(m) || m[idx] == nil { 86 if idx >= len(m) || m[idx] == nil {
95 return nullMetaGetter 87 return nullMetaGetter
96 } 88 }
97 return m[idx] 89 return m[idx]
98 } 90 }
99 91
100 // RawInterface implements the datastore functionality without any of the fancy 92 // RawInterface implements the datastore functionality without any of the fancy
101 // reflection stuff. This is so that Filters can avoid doing lots of redundant 93 // reflection stuff. This is so that Filters can avoid doing lots of redundant
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // - len(keys) > 0 160 // - len(keys) > 0
169 // - all keys are Valid, !Incomplete, and in the current namespace 161 // - all keys are Valid, !Incomplete, and in the current namespace
170 // - none keys of the keys are 'special' (use a kind prefixed with '__ ') 162 // - none keys of the keys are 'special' (use a kind prefixed with '__ ')
171 // - cb is not nil 163 // - cb is not nil
172 DeleteMulti(keys []*Key, cb DeleteMultiCB) error 164 DeleteMulti(keys []*Key, cb DeleteMultiCB) error
173 165
174 // Testable returns the Testable interface for the implementation, or ni l if 166 // Testable returns the Testable interface for the implementation, or ni l if
175 // there is none. 167 // there is none.
176 Testable() Testable 168 Testable() Testable
177 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698