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

Unified Diff: service/datastore/pls.go

Issue 2048933004: Refactor multiarg, split MGS/PLS. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 6 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 92de50c6d132ac72c88b65b16873dd8335206d19..bac10963dbf3c180d930bd2df9fe17f119fd7e34 100644
--- a/service/datastore/pls.go
+++ b/service/datastore/pls.go
@@ -219,15 +219,27 @@ func GetPLS(obj interface{}) interface {
if !v.IsValid() {
panic(fmt.Errorf("cannot GetPLS(%T): failed to reflect", obj))
}
- if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct {
- panic(fmt.Errorf("cannot GetPLS(%T): not a pointer-to-struct", obj))
- }
if v.IsNil() {
panic(fmt.Errorf("cannot GetPLS(%T): pointer-to-struct is nil", obj))
}
- v = v.Elem()
- c := getCodec(v.Type())
- return &structPLS{v, c}
+
+ if v.Kind() == reflect.Ptr {
+ v = v.Elem()
+ if v.Kind() == reflect.Struct {
+ s := structPLS{
+ c: getCodec(v.Type()),
+ o: v,
+ }
+
+ // If our object implements MetaGetterSetter, use this instead of the built-in
+ // PLS MetaGetterSetter.
+ if mgs, ok := obj.(MetaGetterSetter); ok {
+ s.mgs = mgs
+ }
+ return &s
+ }
+ }
+ panic(fmt.Errorf("cannot GetPLS(%T): not a pointer-to-struct", obj))
}
func getMGS(obj interface{}) MetaGetterSetter {

Powered by Google App Engine
This is Rietveld 408576698