This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This commit adds a third hook func type which has access to the
reflect.Value
representations of both thefrom
and theto
objects. This gives all the same power of the existing hook functions (types, kinds, and data can all be retrieved from values), but with the additional benefit of being able to modify theto
object.Change scope
This change is largely backwards compatible. The only change of the public API (other than adding a new hook type) is a change in the signature of
DecodeHookExec
. If that's a sticking point, I think there may be a way around it, but I haven't looked closely at it.Motivation
Exposing the value of
to
opens up some really powerful patterns such as:Defaulter
interfaceUnmarshaler
interfaces (Implement JSON like unmarshaling interface #115)Overall, I think if this is done right, it could really open a lot of possibility for more powerful hook funcs. The API works well, but I plan to play around with it a bit more to make sure it's as flexible as possible. I'm obviously open to any feedback