Repository navigation
Fix #1858: Add query params binding support for anonymous struct pointer field - #1861
Merged
Merged
Conversation
…uct pointer filed
Codecov Report
@@ Coverage Diff @@
## master #1861 +/- ##
==========================================
+ Coverage 89.57% 89.59% +0.02%
==========================================
Files 31 31
Lines 2686 2740 +54
==========================================
+ Hits 2406 2455 +49
- Misses 180 184 +4
- Partials 100 101 +1
Continue to review full report at Codecov.
|
aldas
suggested changes
Apr 27, 2021
| typeField := typ.Field(i) | ||
| structField := val.Field(i) | ||
| if typeField.Anonymous { | ||
| for structField.Kind() == reflect.Ptr { |
Contributor
There was a problem hiding this comment.
I assume you want probably want to use if here instead of for?
| } | ||
| structFieldKind := structField.Kind() | ||
| inputFieldName := typeField.Tag.Get(tag) | ||
| if typeField.Anonymous && structField.Kind() == reflect.Struct && inputFieldName != "" { |
Contributor
There was a problem hiding this comment.
I think this case should return an error and not silently hide the error that developer has made.
Let's just enforce rule that
This is NOT valid/allowed:
result := struct {
*Bar `query:"bar"` // or param:"bar"
}{&Bar{}}This is OK:
result := struct {
*Bar // or json:"bar" as json has its own implementation
}{&Bar{}}
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.
try to fix #1858
if the anonymous struct filed is a pointer, try dig one step deeper and get the underlaying struct