| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 if !reflect.DeepEqual(reflect.Zero(f.Type()).Interface(), f.Inte
rface()) { | 333 if !reflect.DeepEqual(reflect.Zero(f.Type()).Interface(), f.Inte
rface()) { |
| 334 val = f.Interface() | 334 val = f.Interface() |
| 335 if bf, ok := val.(Toggle); ok { | 335 if bf, ok := val.(Toggle); ok { |
| 336 val = bf == On // true if On, otherwise false | 336 val = bf == On // true if On, otherwise false |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 return val, nil | 340 return val, nil |
| 341 } | 341 } |
| 342 | 342 |
| 343 func (p *structPLS) GetMetaDefault(key string, def interface{}) interface{} { |
| 344 return GetMetaDefaultImpl(p.GetMeta, key, def) |
| 345 } |
| 346 |
| 343 func (p *structPLS) SetMeta(key string, val interface{}) (err error) { | 347 func (p *structPLS) SetMeta(key string, val interface{}) (err error) { |
| 344 if err = p.Problem(); err != nil { | 348 if err = p.Problem(); err != nil { |
| 345 return | 349 return |
| 346 } | 350 } |
| 347 idx, ok := p.c.byMeta[key] | 351 idx, ok := p.c.byMeta[key] |
| 348 if !ok { | 352 if !ok { |
| 349 return ErrMetaFieldUnset | 353 return ErrMetaFieldUnset |
| 350 } | 354 } |
| 351 if !p.c.byIndex[idx].canSet { | 355 if !p.c.byIndex[idx].canSet { |
| 352 return fmt.Errorf("gae/helper: cannot set meta %q: unexported fi
eld", key) | 356 return fmt.Errorf("gae/helper: cannot set meta %q: unexported fi
eld", key) |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 return | 536 return |
| 533 } | 537 } |
| 534 c.byName[absName] = i | 538 c.byName[absName] = i |
| 535 } | 539 } |
| 536 } else { | 540 } else { |
| 537 if !st.convert { // check the underlying static type of
the field | 541 if !st.convert { // check the underlying static type of
the field |
| 538 t := ft | 542 t := ft |
| 539 if st.isSlice { | 543 if st.isSlice { |
| 540 t = t.Elem() | 544 t = t.Elem() |
| 541 } | 545 } |
| 542 » » » » v := reflect.New(t).Elem().Interface() | 546 » » » » v := UpconvertUnderlyingType(reflect.New(t).Elem
().Interface()) |
| 543 » » » » v, _ = UpconvertUnderlyingType(v, t) | |
| 544 if _, err := PropertyTypeOf(v, false); err != ni
l { | 547 if _, err := PropertyTypeOf(v, false); err != ni
l { |
| 545 c.problem = me("field %q has invalid typ
e: %s", name, ft) | 548 c.problem = me("field %q has invalid typ
e: %s", name, ft) |
| 546 return | 549 return |
| 547 } | 550 } |
| 548 } | 551 } |
| 549 | 552 |
| 550 if _, ok := c.byName[name]; ok { | 553 if _, ok := c.byName[name]; ok { |
| 551 c.problem = me("struct tag has repeated property
name: %q", name) | 554 c.problem = me("struct tag has repeated property
name: %q", name) |
| 552 return | 555 return |
| 553 } | 556 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 582 switch val { | 585 switch val { |
| 583 case "on", "On", "true": | 586 case "on", "On", "true": |
| 584 return true, nil | 587 return true, nil |
| 585 case "off", "Off", "false": | 588 case "off", "Off", "false": |
| 586 return false, nil | 589 return false, nil |
| 587 } | 590 } |
| 588 return nil, fmt.Errorf("Toggle field has bad/missing default, go
t %q", val) | 591 return nil, fmt.Errorf("Toggle field has bad/missing default, go
t %q", val) |
| 589 } | 592 } |
| 590 return nil, fmt.Errorf("helper: meta field with bad type/value %s/%q", t
, val) | 593 return nil, fmt.Errorf("helper: meta field with bad type/value %s/%q", t
, val) |
| 591 } | 594 } |
| OLD | NEW |