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

Unified Diff: service/datastore/pls.go

Issue 1289323002: Fix miscellaneous prod bugs. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Moar fixes. 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/pls.go
diff --git a/service/datastore/pls.go b/service/datastore/pls.go
index 35eb42dc3c03a94be6313915ea5ed85f40b631b7..6b9b7766b138ad126281b0e729b9065de66ec14b 100644
--- a/service/datastore/pls.go
+++ b/service/datastore/pls.go
@@ -24,11 +24,11 @@ import (
//
// GetPLS supports the following struct tag syntax:
// `gae:"fieldName[,noindex]"` -- an alternate fieldname for an exportable
-// field. When the struct is serialized or deserialized, fieldName will be
+// field. When the struct is serialized or deserialized, fieldName will be
// associated with the struct field instead of the field's Go name. This is
// useful when writing Go code which interfaces with appengine code written
// in other languages (like python) which use lowercase as their default
-// datastore field names.
+// datastore field names.
//
// A fieldName of "-" means that gae will ignore the field for all
// serialization/deserialization.
@@ -87,16 +87,23 @@ import (
// Lines []string
// }
func GetPLS(obj interface{}) PropertyLoadSaver {
+ v, err := getPLSValue(obj)
+ if err != nil {
+ return &structPLS{c: &structCodec{problem: err}}
+ }
+ c := getCodec(v.Type())
+ return &structPLS{v, c}
+}
+
+func getPLSValue(obj interface{}) (reflect.Value, error) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct {
- return &structPLS{c: &structCodec{problem: ErrInvalidEntityType}}
+ return reflect.Value{}, ErrInvalidEntityType
}
if v.IsNil() {
- return &structPLS{c: &structCodec{problem: ErrInvalidEntityType}}
+ return reflect.Value{}, ErrInvalidEntityType
}
- v = v.Elem()
- c := getCodec(v.Type())
- return &structPLS{v, c}
+ return v.Elem(), nil
}
func getCodec(structType reflect.Type) *structCodec {

Powered by Google App Engine
This is Rietveld 408576698