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 // HEAVILY adapted from github.com/golang/appengine/datastore | 5 // HEAVILY adapted from github.com/golang/appengine/datastore |
6 | 6 |
7 package datastore | 7 package datastore |
8 | 8 |
9 import ( | 9 import ( |
10 "fmt" | 10 "fmt" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 189 } |
190 case reflect.Struct: | 190 case reflect.Struct: |
191 switch v.Type() { | 191 switch v.Type() { |
192 case typeOfTime: | 192 case typeOfTime: |
193 project = PTTime | 193 project = PTTime |
194 set = func(x interface{}) { v.Set(reflect.ValueO
f(x)) } | 194 set = func(x interface{}) { v.Set(reflect.ValueO
f(x)) } |
195 case typeOfGeoPoint: | 195 case typeOfGeoPoint: |
196 project = PTGeoPoint | 196 project = PTGeoPoint |
197 set = func(x interface{}) { v.Set(reflect.ValueO
f(x)) } | 197 set = func(x interface{}) { v.Set(reflect.ValueO
f(x)) } |
198 default: | 198 default: |
199 » » » » panic(fmt.Errorf("helper: impossible: %s", typeM
ismatchReason(p.value, v))) | 199 » » » » panic(fmt.Errorf("helper: impossible: %s", typeM
ismatchReason(p.Value(), v))) |
200 } | 200 } |
201 case reflect.Slice: | 201 case reflect.Slice: |
202 project = PTBytes | 202 project = PTBytes |
203 set = func(x interface{}) { | 203 set = func(x interface{}) { |
204 v.SetBytes(reflect.ValueOf(x).Bytes()) | 204 v.SetBytes(reflect.ValueOf(x).Bytes()) |
205 } | 205 } |
206 default: | 206 default: |
207 » » » panic(fmt.Errorf("helper: impossible: %s", typeMismatchR
eason(p.value, v))) | 207 » » » panic(fmt.Errorf("helper: impossible: %s", typeMismatchR
eason(p.Value(), v))) |
208 } | 208 } |
209 | 209 |
210 pVal, err := p.Project(project) | 210 pVal, err := p.Project(project) |
211 if err != nil { | 211 if err != nil { |
212 » » » return typeMismatchReason(p.value, v) | 212 » » » return typeMismatchReason(p.Value(), v) |
213 } | 213 } |
214 if overflow != nil && overflow(pVal) { | 214 if overflow != nil && overflow(pVal) { |
215 return fmt.Sprintf("value %v overflows struct field of t
ype %v", pVal, v.Type()) | 215 return fmt.Sprintf("value %v overflows struct field of t
ype %v", pVal, v.Type()) |
216 } | 216 } |
217 set(pVal) | 217 set(pVal) |
218 } | 218 } |
219 if slice.IsValid() { | 219 if slice.IsValid() { |
220 slice.Set(reflect.Append(slice, v)) | 220 slice.Set(reflect.Append(slice, v)) |
221 } | 221 } |
222 return "" | 222 return "" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 func (p *structPLS) getMetaFor(idx int) (interface{}, bool) { | 327 func (p *structPLS) getMetaFor(idx int) (interface{}, bool) { |
328 st := p.c.byIndex[idx] | 328 st := p.c.byIndex[idx] |
329 val := st.metaVal | 329 val := st.metaVal |
330 if st.canSet { | 330 if st.canSet { |
331 f := p.o.Field(idx) | 331 f := p.o.Field(idx) |
332 if st.convert { | 332 if st.convert { |
333 prop, err := f.Addr().Interface().(PropertyConverter).To
Property() | 333 prop, err := f.Addr().Interface().(PropertyConverter).To
Property() |
334 if err != nil { | 334 if err != nil { |
335 return nil, false | 335 return nil, false |
336 } | 336 } |
337 » » » return prop.value, true | 337 » » » return prop.Value(), true |
338 } | 338 } |
339 | 339 |
340 if !reflect.DeepEqual(reflect.Zero(f.Type()).Interface(), f.Inte
rface()) { | 340 if !reflect.DeepEqual(reflect.Zero(f.Type()).Interface(), f.Inte
rface()) { |
341 val = f.Interface() | 341 val = f.Interface() |
342 if bf, ok := val.(Toggle); ok { | 342 if bf, ok := val.(Toggle); ok { |
343 val = bf == On // true if On, otherwise false | 343 val = bf == On // true if On, otherwise false |
344 } else { | 344 } else { |
345 val = UpconvertUnderlyingType(val) | 345 val = UpconvertUnderlyingType(val) |
346 } | 346 } |
347 } | 347 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 switch val { | 635 switch val { |
636 case "on", "On", "true": | 636 case "on", "On", "true": |
637 return true, nil | 637 return true, nil |
638 case "off", "Off", "false": | 638 case "off", "Off", "false": |
639 return false, nil | 639 return false, nil |
640 } | 640 } |
641 return nil, fmt.Errorf("Toggle field has bad/missing default, go
t %q", val) | 641 return nil, fmt.Errorf("Toggle field has bad/missing default, go
t %q", val) |
642 } | 642 } |
643 return nil, fmt.Errorf("helper: meta field with bad type/value %s/%q", t
, val) | 643 return nil, fmt.Errorf("helper: meta field with bad type/value %s/%q", t
, val) |
644 } | 644 } |
OLD | NEW |