Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Refactor fieldHook function #17

Closed

Conversation

willhug
Copy link
Contributor

@willhug willhug commented May 18, 2017

Summary: I was having a hard time reasoning about the fieldHook function
so I did some refactoring to make it easier to add the embedded struct
fields.

  • Remove the in-place data value updates (this appears to have been an
    optimization, but, it's not necessary and make the code hard to reason
    about)
  • Extract getting the updates struct into it's own function.
  • Extract getting decodable Struct fields into it's own function.
  • Extract applying updates to the srcData into it's own function.
  • Rename variables to be more explicit
  • Don't use the from field, which should be equivalent to
    srcData.Type()

Test Plan: tests pass

#15

Summary: I was having a hard time reasoning about the fieldHook function
so I did some refactoring to make it easier to add the embedded struct
fields.

- Remove the in-place data value updates (this appears to have been an
optimization, but, it's not necessary and make the code hard to reason
about)
- Extract getting the updates struct into it's own function.
- Extract getting decodable Struct fields into it's own function.
- Extract applying updates to the srcData into it's own function.
- Rename variables to be more explicit
- Don't use the `from` field, which should be equivalent to
srcData.Type()

Test Plan: tests pass
@abhinav
Copy link
Contributor

abhinav commented May 19, 2017

IMO this and #18 can be deleted if you just implement field hooks in mapstructure rather than implementing them as a decode hook.

@willhug willhug closed this May 24, 2017
@willhug willhug deleted the structRecurse-part_2.0 branch May 24, 2017 23:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants