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

Unified Diff: service/datastore/multiarg.go

Issue 1289323002: Fix miscellaneous prod bugs. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Remove superfluous function added in PS#1. Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: service/datastore/multiarg.go
diff --git a/service/datastore/multiarg.go b/service/datastore/multiarg.go
index 3efa1493df86692ed1947c2985ba17e753f54b46..76ac4fcffb0c18a46580e0a699985b5873ae409a 100644
--- a/service/datastore/multiarg.go
+++ b/service/datastore/multiarg.go
@@ -214,11 +214,11 @@ func multiArgTypeInterface() multiArgType {
return newKeyObjErr(nk, slot.Elem().Interface())
},
getPM: func(slot reflect.Value) (PropertyMap, error) {
- pls, _ := mkPLSName(slot.Elem().Interface())
+ pls := mkPLS(slot.Elem().Interface())
return pls.Save(true)
},
setPM: func(slot reflect.Value, pm PropertyMap) error {
- pls, _ := mkPLSName(slot.Elem().Interface())
+ pls := mkPLS(slot.Elem().Interface())
return pls.Load(pm)
},
setKey: func(slot reflect.Value, k Key) {
@@ -228,15 +228,19 @@ func multiArgTypeInterface() multiArgType {
}
func newKeyObjErr(nk newKeyFunc, src interface{}) (Key, error) {
- pls, name := mkPLSName(src)
+ pls := mkPLS(src)
if key, _ := pls.GetMetaDefault("key", nil).(Key); key != nil {
return key, nil
}
// get kind
- kind := pls.GetMetaDefault("kind", name).(string)
- if kind == "" {
- return nil, fmt.Errorf("unable to extract $kind from %v", src)
+ kindIface, err := pls.GetMeta("kind")
iannucci 2015/08/15 21:50:54 I think you could GetMetaDefault("kind", "").(stri
dnj (Google) 2015/08/16 06:11:06 Done.
+ if err != nil {
+ return nil, fmt.Errorf("unable to extract $kind from %v: %s", src, err)
+ }
+ kind, ok := kindIface.(string)
+ if !ok {
+ return nil, fmt.Errorf("$kind is not a string: %T", kind)
}
// get id - allow both to be default for default keys
@@ -250,7 +254,7 @@ func newKeyObjErr(nk newKeyFunc, src interface{}) (Key, error) {
}
func setKey(src interface{}, key Key) {
- pls, _ := mkPLSName(src)
+ pls := mkPLS(src)
if pls.SetMeta("key", key) == ErrMetaFieldUnset {
if key.StringID() != "" {
pls.SetMeta("id", key.StringID())
@@ -262,14 +266,9 @@ func setKey(src interface{}, key Key) {
}
}
-func mkPLSName(o interface{}) (PropertyLoadSaver, string) {
- if pls, ok := o.(*structPLS); ok {
- return pls, pls.o.Type().Name()
- }
+func mkPLS(o interface{}) PropertyLoadSaver {
if pls, ok := o.(PropertyLoadSaver); ok {
- return pls, ""
+ return pls
}
- pls := GetPLS(o)
- name := pls.(*structPLS).o.Type().Name()
- return pls, name
+ return GetPLS(o)
}

Powered by Google App Engine
This is Rietveld 408576698