echo
echo copied to clipboard
Allow binders to be chained together to create multi-source binder
There are (rare) cases when you would want to bind value from different sources. So this PR allows binders to be chained together to create multi-source binder.
This has few use-cases because we have ValueBinder
s only for Path/Query/Form and most of the time if multi-source binding is needed we talk about body (ala JSON) + some other source (ala query).
Example:
// bound query params should have priority over path params
b := QueryParamsBinder(c).UseBefore(PathParamsBinder(c))
or
// bound params priority:
// 1. Path params
// 2. Query params
// 3. Form fields
b := PathParamsBinder(c).UseBefore(QueryParamsBinder(c)).UseBefore(FormFieldBinder(c))
I am not sure if this name UseBefore
is best. I considered Combine
, CombineWith
, CombineBefore
, Use
, Chain
*Before
is added as suffix to make it clear there is order of binding. *Before
indicates that left side binder value is used before right side binder value. But I am at the moment no even sure that people would read/understand it like I do.
I am open to suggestions for naming it.
p.s. this is low priority, low value change
Codecov Report
Base: 92.35% // Head: 92.38% // Increases project coverage by +0.02%
:tada:
Coverage data is based on head (
510f12d
) compared to base (8f2bf82
). Patch coverage: 100.00% of modified lines in pull request are covered.
Additional details and impacted files
@@ Coverage Diff @@
## master #2311 +/- ##
==========================================
+ Coverage 92.35% 92.38% +0.02%
==========================================
Files 37 37
Lines 4436 4450 +14
==========================================
+ Hits 4097 4111 +14
Misses 247 247
Partials 92 92
Impacted Files | Coverage Δ | |
---|---|---|
binder.go | 100.00% <100.00%> (ø) |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
@lammel when you have time. This is low priority PR, so no pressure here :)