-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fluent Binder for Query/Path/Form binding (#1717) #1736
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1736 +/- ##
==========================================
+ Coverage 86.66% 89.43% +2.76%
==========================================
Files 29 31 +2
Lines 2063 2594 +531
==========================================
+ Hits 1788 2320 +532
Misses 175 175
+ Partials 100 99 -1
Continue to review full report at Codecov.
|
weird test failures. somewhere between Go1.13 and 1.14/1.15 |
3757f51
to
952779f
Compare
Looks great @aldas . Going to review soon. |
CI: report coverage for latest go (1.15) version
952779f
to
3751b5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't reviewed the UT yet (it's quite late here 😉)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new way of Binding is awesome!!!
Thanks also for the effort on writing that amount of tests
When reviews are done, issues fixed and it is time to merge - please merge with squashing commits. |
* Improve request binding documentation. See Echo pull request #1736 (labstack/echo#1736) * Split binding to dedicated guide, some wording improvements * Bind example more alike with other router examples. Mention `UnixTimeNano()` as supported fluent binder function Co-authored-by: Roland Lammel <rl@neotel.at>
Proposed implementation for #1717
Following functions provide handful of methods for binding to Go native types from request query or path parameters.
Example:
For every supported type there are following methods:
<Type>("param", &destination)
- if parameter value exists then binds it to given destination of that type i.e Int64(...).Must<Type>("param", &destination)
- parameter value is required to exist, binds it to given destination of that type i.e MustInt64(...).<Type>s("param", &destination)
- (for slices) if parameter values exists then binds it to given destination of that type i.e Int64s(...).Must<Type>s("param", &destination)
- (for slices) parameter value is required to exist, binds it to given destination of that type i.e MustInt64s(...).for some slice types
BindWithDelimiter("param", &dest, ",")
supports slitting parameter values before type conversion is donei.e. URL
/api/search?id=1,2,3&id=1
can be bind to[]int64{1,2,3,1}
FailFast
flags binder to stop binding after first bind error during binder call chain. Enabled by default.BindError()
returns first bind error from binder and resets errors in binder. Useful along withFailFast()
methodto do binding and returns on first problem
BindErrors()
returns all bind errors from binder and resets errors in binder.Types that are supported:
bytes()
. Use BindUnmarshaler/CustomFunc to convert value from base64 etc to []byte{})func(values []string) []error
Added some naive benchmarks to compare different implementations (query params)
BenchmarkDefaultBinder_BindInt64_single
uses DefaultBinder to bind single int64 valueBenchmarkValueBinder_BindInt64_single
uses new binder to bind single int64 valueBenchmarkRawFunc_Int64_single
just gets param from contexts, parses it with utility method and sets to variableBenchmarkDefaultBinder_BindInt64_10_fields
uses DefaultBinder to bind 10 fields to structBenchmarkValueBinder_BindInt64_10_fields
uses new binder to bind 10 fields to struct@lammel @pafuent what do you think?