mitchellh / mapstructure

Go library for decoding generic map values into native Go structures and vice versa.
https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
MIT License
7.93k stars 677 forks source link

Is it possible to add `DecodeHook` with name? #295

Closed iyear closed 2 years ago

iyear commented 2 years ago

Thanks for such a good library! In https://github.com/mitchellh/mapstructure/blob/main/mapstructure.go#L459-L461 I found that all three DecodeHooks can't get the corresponding name.

In some scenarios, I need to get the corresponding name as a unique key, can I add three new DecodeHooks that carry the name parameter?

For example:

type DecodeHookFuncTypeWithName func(name string, reflect.Type, reflect.Type, interface{}) (interface{}, error)
type DecodeHookFuncKindWithName func(name string, reflect.Kind, reflect.Kind, interface{}) (interface{}, error)
type DecodeHookFuncValueWithName func(name string, from reflect.Value, to reflect.Value) (interface{}, error)