mitchellh/mapstructure — pull request #20 by shutej (2014-12-23 21:43:48+00:00)
Title: DO NOT MERGE: Proposal for how to rework DecodeHook

Mitchell,

I like this package, however I've had a lot of difficulty adapting it to use time.Time.

I notice that one of the things you do is detect `reflect.Kind` and then indicate how to operate the conversion on that basis. An alternative approach would be to pass `reflect.Type`, instead, which has the notable advantage of allowing the user to detect *which* reflect.Struct the decoder is being asked to modify.

The problem with `reflect.Type`, however, is that some types actually don't have a cheap/trivial assignment operator. `time.Time` is one of those types. So I think it may be best to go whole-hog and simply pass `reflect.Value` (which of course has access to both `reflect.Kind` and `reflect.Type`). That's what this change does.

Note that the `DecoderHook`, if it exists, should return one of `ErrDecodeHookAccepted` to indicate that it has taken responsibility for `to.Set(...)`, or `ErrDecodeHookRejected` which is just a slightly more readable alias for `error(nil)`.