| Index: service/datastore/properties.go
|
| diff --git a/service/datastore/properties.go b/service/datastore/properties.go
|
| index 4267d029ad7c7387073cfb2a70e5c369aec6628c..95a4e6069267aa43061d99b2a906bc39a2713619 100644
|
| --- a/service/datastore/properties.go
|
| +++ b/service/datastore/properties.go
|
| @@ -649,19 +649,6 @@ type MetaGetter interface {
|
| // // BadFlag Toggle `gae:"$flag3"` // ILLEGAL
|
| // }
|
| GetMeta(key string) (interface{}, error)
|
| -
|
| - // GetMetaDefault is GetMeta, but with a default.
|
| - //
|
| - // If the metadata key is not available, or its type doesn't equal the
|
| - // homogenized type of dflt, then dflt will be returned.
|
| - //
|
| - // Type homogenization:
|
| - // signed integer types -> int64
|
| - // bool -> Toggle fields (bool)
|
| - //
|
| - // Example:
|
| - // pls.GetMetaDefault("foo", 100).(int64)
|
| - GetMetaDefault(key string, dflt interface{}) interface{}
|
| }
|
|
|
| // PropertyLoadSaver may be implemented by a user type, and Interface will
|
| @@ -679,11 +666,6 @@ type PropertyLoadSaver interface {
|
| // then the PropertyMap contains all the metadata (e.g. '$meta' fields)
|
| // which was held by this PropertyLoadSaver.
|
| Save(withMeta bool) (PropertyMap, error)
|
| -
|
| - // Problem indicates that this PLS has a fatal problem. Usually this is
|
| - // set when the underlying struct has recursion, invalid field types, nested
|
| - // slices, etc.
|
| - Problem() error
|
| }
|
|
|
| // MetaGetterSetter is the subset of PropertyLoadSaver which pertains to
|
| @@ -787,11 +769,6 @@ func (pm PropertyMap) GetAllMeta() PropertyMap {
|
| return ret
|
| }
|
|
|
| -// GetMetaDefault is the implementation of PropertyLoadSaver.GetMetaDefault.
|
| -func (pm PropertyMap) GetMetaDefault(key string, dflt interface{}) interface{} {
|
| - return GetMetaDefaultImpl(pm.GetMeta, key, dflt)
|
| -}
|
| -
|
| // SetMeta implements PropertyLoadSaver.SetMeta. It will only return an error
|
| // if `val` has an invalid type (e.g. not one supported by Property).
|
| func (pm PropertyMap) SetMeta(key string, val interface{}) error {
|
| @@ -833,18 +810,28 @@ func isMetaKey(k string) bool {
|
| return k == "" || k[0] == '$'
|
| }
|
|
|
| -// GetMetaDefaultImpl is the implementation of PropertyLoadSaver.GetMetaDefault.
|
| +// GetMetaDefault is a helper for GetMeta, allowing a default value.
|
| +//
|
| +// If the metadata key is not available, or its type doesn't equal the
|
| +// homogenized type of dflt, then dflt will be returned.
|
| //
|
| -// It takes the normal GetMeta function, the key and the default, and returns
|
| -// the value according to PropertyLoadSaver.GetMetaDefault.
|
| -func GetMetaDefaultImpl(gm func(string) (interface{}, error), key string, dflt interface{}) interface{} {
|
| +// Type homogenization:
|
| +// signed integer types -> int64
|
| +// bool -> Toggle fields (bool)
|
| +//
|
| +// Example:
|
| +// pls.GetMetaDefault("foo", 100).(int64)
|
| +func GetMetaDefault(getter MetaGetter, key string, dflt interface{}) (interface{}, error) {
|
| dflt = UpconvertUnderlyingType(dflt)
|
| - cur, err := gm(key)
|
| + cur, err := getter.GetMeta(key)
|
| if err != nil {
|
| - return dflt
|
| + if err == ErrMetaFieldUnset {
|
| + return dflt, nil
|
| + }
|
| + return nil, err
|
| }
|
| if dflt != nil && reflect.TypeOf(cur) != reflect.TypeOf(dflt) {
|
| - return dflt
|
| + return dflt, nil
|
| }
|
| - return cur
|
| + return cur, nil
|
| }
|
|
|