mapstructure
mapstructure copied to clipboard
Allowed hook to skip the decode
If input is zero, add and option to skip the outVal.Set(reflect.Zero(outVal.Type()))
https://github.com/mitchellh/mapstructure/blob/95075d6e1a88d608e5258a054d7f0de9401f255e/mapstructure.go#L403-L411
If this is acceptable, I can make a pr
I don't understand the motivation here, if you can show a failed test case that would help.
With patch can do this
func TestPatch(t *testing.T) {
a := &Data{
Name: "a",
Age: 10,
}
path := &Data{
Name: "neo",
}
throwError(mapstructure.Decode(path, a))
assert.Equal(t, a.Age, 10)
}
type Data struct {
Name string
Age int
}
Hope allowed DecodeHook to return a skip, like
type DecodeHookFuncValueSkip func(from reflect.Value, to reflect.Value) (interface{}, bool, error)
If skipped, should abort current decode.
Add a special error can keep everything unchang, and allowed to skip the rest decode.
var ErrSkip = errors.New("skip")