Path params won't bind. #2333
Answered
by
chrislentz
chrislentz
asked this question in
Q&A
-
Can anyone help me understand why Echo wont bind my path parameters? The query param binds successfully, but the 2 path params are empty when I log the requestData struct after binding.
type TestRequest struct {
TestParamOne string `param:"test_param_one"`
TestParamTwo string `param:"test_param_two"`
TestQueryOne string `query:"test_query_one"`
}
func main() {
app := echo.New()
app.GET("/test/:test_param_one/:test_param_two", func(c echo.Context) (err error) {
var requestData TestRequest
fmt.Println(c.Param("test_param_one")) // This works.
fmt.Println(c.Param("test_param_two")) // This works.
// Bind request data
if err = c.Bind(&requestData); err != nil {
fmt.Println(err)
return err
}
fmt.Printf("%#v\n", requestData) // TestParamOne & TestParamTwo are empty. TestQueryOne binded sucessfully.
return c.String(http.StatusOK, "OK")
})
app.Logger.Fatal(app.Start(":8181"))
}
|
Beta Was this translation helpful? Give feedback.
Answered by
chrislentz
Nov 7, 2022
Replies: 1 comment 1 reply
-
I was able to resolve the issue. It turns out I was running an outdated version of Echo. I upgraded to |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
chrislentz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was able to resolve the issue. It turns out I was running an outdated version of Echo. I upgraded to
v4.9.1
and it is working as expected.