feat(binding): use encoding.UnmarshalText by default via build tag#4566
Open
takanuva15 wants to merge 2 commits intogin-gonic:masterfrom
Open
feat(binding): use encoding.UnmarshalText by default via build tag#4566takanuva15 wants to merge 2 commits intogin-gonic:masterfrom
takanuva15 wants to merge 2 commits intogin-gonic:masterfrom
Conversation
Types like uuid.UUID implement encoding.TextUnmarshaler but previously required an explicit `parser=encoding.TextUnmarshaler` struct tag to be used during form/query/URI binding. This meant ShouldBind/ShouldBindQuery would fail with unhelpful errors like: ["45e1f85e-bca5-458d-bd9c-c56edd8f847b"] is not valid value for uuid.UUID This change makes trySetCustom automatically check for encoding.TextUnmarshaler as a fallback after BindUnmarshaler, so any type implementing TextUnmarshaler (uuid.UUID, net.IP, custom types, etc.) works out of the box with no extra tags. Precedence order: 1. BindUnmarshaler (UnmarshalParam) 2. encoding.TextUnmarshaler (UnmarshalText) 3. Default type-based binding time.Time is explicitly excluded from automatic TextUnmarshaler handling since gin has dedicated time parsing with time_format, time_utc, and time_location struct tags. Fixes gin-gonic#2423 Signed-off-by: Varun Chawla <varun_6april@hotmail.com>
59b827d to
513eec4
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4566 +/- ##
==========================================
- Coverage 99.21% 98.31% -0.90%
==========================================
Files 42 51 +9
Lines 3182 3152 -30
==========================================
- Hits 3157 3099 -58
- Misses 17 44 +27
- Partials 8 9 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
29f5df0 to
bee5bd3
Compare
bee5bd3 to
07bcf34
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With this PR, users can set the build tag
gin_bind_encodingto configure gin binding to use encoding.UnmarshalText by default. This will not break existing servers since the build tag must be specified to enable the behavior.Credit to #4540 for the original default binding implementation
relates to #4540
relates to #4203
relates to #4177
relates to #3933
relates to #3045
relates to #3036
relates to #2673
relates to #2631
relates to #2510
closes #2423
closes #3060
Example
Test it with:
Result
{"Uuid":"70d9b500-fa26-11dd-876f-322495cdf0f7"}Pull Request Checklist
Please ensure your pull request meets the following requirements:
masterbranch.docs/doc.md.Thank you for contributing!