-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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(binding): Support custom BindUnmarshaler for binding. #3933
Conversation
@appleboy Hi, Boyi, could you take a look at this PR. Any help would be greatly appreciated. |
I forgot the build tags, I'll fix it. |
I move the newly added interface to |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3933 +/- ##
==========================================
- Coverage 99.21% 99.18% -0.03%
==========================================
Files 42 43 +1
Lines 3182 2716 -466
==========================================
- Hits 3157 2694 -463
+ Misses 17 12 -5
- Partials 8 10 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
- added UnmarshalParam to support query param gin-gonic/gin#3933
Feature
Add
binding.BindUnmarshaler
interface to support custom unmarshaling (from the suggestion in #2673)Description
This PR is inspired by the information provided on the following page: labstack/echo/v4#BindUnmarshaler and PR-3045.
As ssoroka (the author of PR-3045) mentioned:
Therefore, I would like to open a new pull request to implement this feature. However, I have identified two potential issues with PR-3045:
PR-3045 also introduces support for the
encoding.TextUnmarshaler
interface. I believe there might be compatibility issues with this approach. Instead, I suggest that users implement the new interface binding.BindUnmarshaler to achieve the desired custom unmarshaler functionality.In order to support arrays and slices, PR-3045 uses
vs[0]
to retrieve the first item. This approach may be susceptible to boundary issues. Upon closer examination of the implementation, I found that addressing this complexity might be challenging. As a temporary solution, I have decided not to support this functionality for arrays and slices. If there is a future demand from other users, we can consider implementing it at that time.Usage
Test it with:
curl 'localhost:8088/test?birthday=2000-01-01'
Result
"2000/01/01"
Testing
binding/form_mapping_test.go
gin_test.go
References