private/protocol/json/jsonutil: avoid unnecessary allocation in unmarshalScalar
@@ -172,9 +172,6 @@ func unmarshalMap(value reflect.Value, data interface{}, tag reflect.StructTag)
}
func unmarshalScalar(value reflect.Value, data interface{}, tag reflect.StructTag) error {
- errf := func() error {
- return fmt.Errorf("unsupported value: %v (%s)", value.Interface(), value.Type())
- }
switch d := data.(type) {
case nil:
@@ -197,7 +194,7 @@ func unmarshalScalar(value reflect.Value, data interface{}, tag reflect.StructTa
}
value.Set(reflect.ValueOf(v))
default:
- return errf()
+ return fmt.Errorf("unsupported value: %v (%s)", value.Interface(), value.Type())
}
case float64:
switch value.Interface().(type) {
@@ -210,14 +207,14 @@ func unmarshalScalar(value reflect.Value, data interface{}, tag reflect.StructTa
t := time.Unix(int64(d), 0).UTC()
value.Set(reflect.ValueOf(&t))
default:
- return errf()
+ return fmt.Errorf("unsupported value: %v (%s)", value.Interface(), value.Type())
}
case bool:
switch value.Interface().(type) {
case *bool:
value.Set(reflect.ValueOf(&d))
default:
- return errf()
+ return fmt.Errorf("unsupported value: %v (%s)", value.Interface(), value.Type())
}
default:
return fmt.Errorf("unsupported JSON value (%v)", data)
