-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
echo.Bind not working while binding query params to a struct with another nested anonymous struct's pointer in it #1858
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
Comments
pwli0755
pushed a commit
to pwli0755/echo
that referenced
this issue
Apr 25, 2021
…uct pointer filed
aldas
pushed a commit
that referenced
this issue
May 8, 2021
I'm having kinda the same issue in version 4.12.0. Expected behaviourcurl --request POST http://localhost:8080/buy?product=card { "Product": "card" } Actual behaviour{ "Product": "" } Working code to debugpackage main
import (
"log"
"net/http"
"github.com/labstack/echo/v4"
)
type Request struct {
Product string `query:"product"`
}
func main() {
e := echo.New()
e.POST("/buy", func(c echo.Context) error {
req := Request{}
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
return c.JSON(http.StatusOK, req)
})
if err := e.Start(":8080"); err != nil {
log.Fatal(err)
}
} |
Query params are not bound for POST method. Lines 122 to 131 in 88c379f
Something like that would work binder := echo.DefaultBinder{}
e.POST("/buy", func(c echo.Context) error {
req := Request{}
if err := binder.BindQueryParams(c, &req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
return c.JSON(http.StatusOK, req)
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue Description
bind the query params into target struct's anonymous filed which is a pointer to struct,
note that if the payload in http body, it seems bind works fine,
issue happens only when bind query params with a struct with an anonymous filed which is a pointer to struct
Checklist
Expected behaviour
Actual behaviour
bind skips the anonymous filed
Steps to reproduce
curl 'http://localhost:8000/test?limit=1'
Working code to debug
Version/commit
v4.2.3-0.20210417194748-3b07058a1d8f
The text was updated successfully, but these errors were encountered: