-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
Proposal: built in support for protobuf wrapper types #207
Comments
Thanks for opening a new issue. The team has been notified and will review it as soon as possible. |
I'm prefer to avoid adding deps for protobuf. This types easy can be set via reflection (switch on Type().Kind.String and fill Value struct field) |
this is example code https://github.com/unistack-org/micro/blob/v3/util/reflect/struct.go#L390 |
@vtolstov seems reasonable to leave the dependency out of this library, I'll close this out. To your comment about this being doable with reflection and the example you linked. Are you suggesting that's a better alternative to the codesnippet I posted above? Is there some drawback to approach that I'm missing here? |
In you case you depend on protobuf library and code base, with my -!only reflection used. |
I see, so you wouldn't mind adding in a transformer that checked the types by string and set the values? You just don't want to directly depend on the protobuf library. In that case I'll reopen this. |
Should it still be implemented as a transformer, or should this logic be built into the default merging logic? Assuming we'd want the former, but I could see arguments for the later (such as that the merging behavior for these types would be more correct by default given their purpose) |
It was already implemented in #211 :) |
Hiya, firstly, thank you for this project, of the bunch out there offering similar functionality this package is the only one I found that really does the job right and offered enough configuration to handle edge cases or quirks of my particular needs.
One such need involved merging protobuf's wrapper types
Ref: https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto
These types are really handy for go projects as the allow differentiating between "not set" and zero values in api parameters.
Representation in Go for
BoolValue
I was running into an issue with
mergo.Merge
when merging aBoolValue
field. Both the source and dest fields had the field set (non nil). However the underlyingValue
in the destination wasfalse
whereas the source wastrue
. Mergo understandably thought the right action was to overwriteValue
withtrue
being a non-zero value (as it went to merge at the field level of the struct), however the presence of a non-nil wrapper type in the destination means it was explicitly set and shouldn't be overwritten.mergo Transformers to the rescue! Thankfully y'all have a great mechanism for overriding this behavior and just as I thought I was screwed (
proto.Merge
is garbage btw), I was able to write a pretty simply transformer that resolved the issue. This ticket is mostly to say thanks for the great project and to see if adding something like the below transformer to the project would be useful.The text was updated successfully, but these errors were encountered: