-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use isReflectNil instead of isEmptyValue to gate Transformers #1
Conversation
Not sure what's going on with travis, as same tests are passing locally :\ |
Can you dig deeper to see if there are versions that are not matching up? |
I added a build matrix for various releases of go and it seems this works with >= 1.13 I see 1.13 introduced some changes to the reflect package, maybe that's related |
I'm not familiar with this codebase so can't review. I'll trust you with this one for now.
|
Mergo handles merges with zero-value fields as follows: 1. dst: true src: false -> dst: true 2. dst: nil src: false -> dst: false 3. dst: nil src: true -> dst: true 4. dst: false src: true -> dst: true In some cases (darccio#166) it may be desirable to change this default behaviour using a custom Transformer, for example to not overwrite 'dst' when it's already set to 'false' (or '0' etc). Unfortunately, in such cases (when dst holds a zero-value) no Transformers can be applied due to the way these are gated (darccio#166). Here we are changing how transformers are gated by using the isReflectNil function insted of isEmptyValue. Note that: - this change doesn't affect the default behaviour of mergo, as it only affects how transformers are gated - since custom transformers need to match data types in order to execute, this shouldn't affect any existing transformers either
7d606d2
to
32bd3e7
Compare
Done! |
Go ahead and merge and do a release. |
We recently forked and patched mergo (Kong/mergo#1) to improve the way we can handle zero-value fields with defaults values. Currently, if an entity field is set with a zero-value (e.g. a target with weight=0, a route with strip_path=false etc.), we will overwrite it when merging it with its default if this is not a zero-value itself. This update the mergo dependence and add a custom transformer to support such cases as well. Also, add few test cases with zero-value fields.
We recently forked and patched mergo (Kong/mergo#1) to improve the way we can handle zero-value fields with defaults values. Currently, if an entity field is set with a zero-value (e.g. a target with weight=0, a route with strip_path=false etc.), we will overwrite it when merging it with its default if this is not a zero-value itself. This update the mergo dependence and add a custom transformer to support such cases as well. Also, add few test cases with zero-value fields.
Original upstream PR with reasoning behind this patch: darccio#203
Couple of additional comments:
mergo
(see below), but it only affects how transformers are gated