-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
Custom transformer can't get around isEmptyValue logic #118
Comments
This is phrased as a question I suppose but my intent is more closely represented by: I hit a piece of logic which wasn't clear to me that I couldn't/shouldn't be able to override. I would like a way to either:
And the follow up is that if there is hard 'no' to both of those ideas (I'm happy to try and implement the fixes) then I must be missing some understanding about why that logic exists and is non-overridable (and I'd love to be enlightened). Thanks! Let me know if you are open to one or both of those ideas and I can try to implement. Obviously the former is much more trivial than a completely new override for handling empty/nil. |
Did you figure out a solution for this? |
No, I worked around this entirely by saving the values I needed, running mergo, then applying fixups to the merge logic manually. |
Sorry for not getting this earlier. Please, can you provide an example? Since this issue was created, some features have landed in master, but I'm not sure what you are trying to accomplish. I get the idea of what you want but not the context where it would be used. Mergo is getting too much complex and the corner cases are getting harder to understand without more explanation. |
I was specifically trying to write a transformer so that I could differentiate between nil slices (the zero value) and an empty slice. However, the transformer doesnt get applied because of this line https://github.com/imdario/mergo/blob/master/merge.go#L66
Which says it only applies the custom transform if the dst value is not
isEmptyValue
which mergo defines aslen(slice)==0
So even when I define a custom transform I can't implement this as I wanted. What is the rational for the extra empty check? It seemed intuitive to me that the user's transformation would always get applied when it matched the type. Seems like this is related to #89 and other bool/zero value issues.
The text was updated successfully, but these errors were encountered: