OLD | NEW |
---|---|
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 "reflect" | 8 "reflect" |
9 ) | 9 ) |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 // // split on "|" | 151 // // split on "|" |
152 // // assign to n.First, n.Last | 152 // // assign to n.First, n.Last |
153 // } | 153 // } |
154 // | 154 // |
155 // type Person struct { | 155 // type Person struct { |
156 // Name `gae:"$id"` | 156 // Name `gae:"$id"` |
157 // } | 157 // } |
158 func GetPLS(obj interface{}) interface { | 158 func GetPLS(obj interface{}) interface { |
159 PropertyLoadSaver | 159 PropertyLoadSaver |
160 MetaGetterSetter | 160 MetaGetterSetter |
161 Problem() error | |
dnj
2015/12/11 06:36:17
Since Problem() is only used by tests, why export
| |
161 } { | 162 } { |
162 v := reflect.ValueOf(obj) | 163 v := reflect.ValueOf(obj) |
163 if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct { | 164 if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct { |
164 return &structPLS{c: &structCodec{problem: ErrInvalidEntityType} } | 165 return &structPLS{c: &structCodec{problem: ErrInvalidEntityType} } |
165 } | 166 } |
166 if v.IsNil() { | 167 if v.IsNil() { |
167 return &structPLS{c: &structCodec{problem: ErrInvalidEntityType} } | 168 return &structPLS{c: &structCodec{problem: ErrInvalidEntityType} } |
168 } | 169 } |
169 v = v.Elem() | 170 v = v.Elem() |
170 c := getCodec(v.Type()) | 171 c := getCodec(v.Type()) |
(...skipping 12 matching lines...) Expand all Loading... | |
183 c, ok := structCodecs[structType] | 184 c, ok := structCodecs[structType] |
184 structCodecsMutex.RUnlock() | 185 structCodecsMutex.RUnlock() |
185 if ok { | 186 if ok { |
186 return c | 187 return c |
187 } | 188 } |
188 | 189 |
189 structCodecsMutex.Lock() | 190 structCodecsMutex.Lock() |
190 defer structCodecsMutex.Unlock() | 191 defer structCodecsMutex.Unlock() |
191 return getStructCodecLocked(structType) | 192 return getStructCodecLocked(structType) |
192 } | 193 } |
OLD | NEW |