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

Unified Diff: service/rawdatastore/datastore_impl.go

Issue 1259463002: Add BoolFlag for rawdatastore. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: improve error Created 5 years, 5 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 | « no previous file | service/rawdatastore/datastore_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/rawdatastore/datastore_impl.go
diff --git a/service/rawdatastore/datastore_impl.go b/service/rawdatastore/datastore_impl.go
index 2ea0ae9e161766ff3087f39318f8bee80643eb69..1b10daffe5676d61c1741675d052828323c13de4 100644
--- a/service/rawdatastore/datastore_impl.go
+++ b/service/rawdatastore/datastore_impl.go
@@ -332,6 +332,9 @@ func (p *structPLS) GetMeta(key string) (interface{}, error) {
if st.canSet {
if !reflect.DeepEqual(reflect.Zero(f.Type()).Interface(), f.Interface()) {
val = f.Interface()
+ if bf, ok := val.(Toggle); ok {
+ val = bf == On // true if On, otherwise false
+ }
}
}
return val, nil
@@ -348,6 +351,14 @@ func (p *structPLS) SetMeta(key string, val interface{}) (err error) {
if !p.c.byIndex[idx].canSet {
return fmt.Errorf("gae/helper: cannot set meta %q: unexported field", key)
}
+ // setting a BoolField
+ if b, ok := val.(bool); ok {
+ if b {
+ val = On
+ } else {
+ val = Off
+ }
+ }
p.o.Field(idx).Set(reflect.ValueOf(val))
return nil
}
@@ -557,6 +568,14 @@ func convertMeta(val string, t reflect.Type) (interface{}, error) {
return int64(0), nil
}
return strconv.ParseInt(val, 10, 64)
+ case typeOfToggle:
+ switch val {
+ case "on", "On", "true":
+ return true, nil
+ case "off", "Off", "false":
+ return false, nil
+ }
+ return nil, fmt.Errorf("Toggle field has bad/missing default, got %q", val)
}
- return nil, fmt.Errorf("helper: meta field with bad type/value %s/%s", t, val)
+ return nil, fmt.Errorf("helper: meta field with bad type/value %s/%q", t, val)
}
« no previous file with comments | « no previous file | service/rawdatastore/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698