-
Notifications
You must be signed in to change notification settings - Fork 8k
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
ShouldBindQuery panic if query string is empty #3739
Comments
I can work around this by instantiating params, or by passing in a struct instead of a pointer to a struct. // works
params := &Params{}
c.ShouldBindQuery(¶ms)
// works
var params Params
c.ShouldBindQuery(params)
// does not work
var params *Params
c.ShouldBindQuery(¶ms) I primarily use |
It's a error about improper use of pointers. Modify |
Make sure your ShouldBindQuery accepted type is *Param, So if you define params like this
Then you call should like this:
It will work fine :) |
Thanks @VarusHsu, that works! I think the confusion stems from the discrepancy between // valid
var params *Params
c.ShouldBindJSON(¶ms)
// invalid
var params *Params
c.ShouldBindQuery(¶ms) |
Actually this results in a panic as well |
Description
I have a simple web server with a search api that accepts three string query parameters:
a
,b
, andc
. I can useShouldBindQuery
to bind these parameters to a struct, but if I call the endpoint without any query in the path the handler panics (and recovers).How to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: