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

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: Rebarse? 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
« no previous file with comments | « service/datastore/multiarg.go ('k') | service/datastore/pls_impl.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/pls.go
diff --git a/service/datastore/pls.go b/service/datastore/pls.go
index 62b459b413fd811f55676dd8175be88f2967779b..15fe6c3b2cca67affe2e854d3c0c5d5986f54dd0 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))
+ panic(fmt.Errorf("cannot GetPLS(%T): pointer is nil", obj))
+ }
+
+ 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
+ }
}
- v = v.Elem()
- c := getCodec(v.Type())
- return &structPLS{v, c}
+ panic(fmt.Errorf("cannot GetPLS(%T): not a pointer-to-struct", obj))
}
func getMGS(obj interface{}) MetaGetterSetter {
« no previous file with comments | « service/datastore/multiarg.go ('k') | service/datastore/pls_impl.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698