-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Regression: binding a map is not allowed anymore #988
Comments
Has this issue been solved? I meet it today. my code as following: maybe you need to repear it locally since go playground cannot listen port. |
me too |
I am not sure what is the issue but the following code works package main
import (
"net/http"
"github.com/labstack/echo"
)
func main() {
e := echo.New()
e.GET("/test", func(c echo.Context) error {
p := map[string]interface{}{}
if err := c.Bind(&p); err != nil {
return err
}
return c.JSON(http.StatusOK, p)
})
e.Start("127.0.0.1:8080")
} curl -X GET \
http://localhost:8080/test \
-H 'Content-Type: application/json' \
-d '{
"a": 1,
"b": 2
}' |
thanks for your reply, |
How are you sending the data? |
i've tested both following format:
and |
after a deep dive to echo.
Do it possible to support |
@narrowizard Just push a fix, let me know how it works out for you. |
it works now except that it causes a panic if ptr is of type Lines 97 to 98 in da45981
anyway, thanks for your impl. @vishr |
Signed-off-by: Vishal Rana <vr@labstack.com>
Fixed.
… On Jul 14, 2019, at 10:36 PM, NaRro ***@***.***> wrote:
it works now except that it causes a panic if ptr is of type map[string]interface{} with nil value. it's better to add an nil check before set value.
https://github.com/labstack/echo/blob/da459814916905d4ea1208ded02f15924fa6a114/bind.go#L97-L98 <https://github.com/labstack/echo/blob/da459814916905d4ea1208ded02f15924fa6a114/bind.go#L97-L98>
var p map[string]interface
ctx.Bind(&p) // here panic `assignment to entry in nil map`
anyway, thanks for your impl. @vishr <https://github.com/vishr>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#988?email_source=notifications&email_token=AACMVNG7NDBELHXZYYOELRDP7QEFBA5CNFSM4DWOQOB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ4X7NY#issuecomment-511279031>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AACMVNBKBP6QJOHLLMTT3XTP7QEFBANCNFSM4DWOQOBQ>.
|
Well, it looks like binding a map can still panic with echo v4.1.10: https://travis-ci.org/cozy/cozy-stack/jobs/573823462#L696-L703. The code is in this PR: cozy/cozy-stack#2015. |
@nono I will look into this today. |
@vishr
|
Folks, I need help here. Let me know if you are willing to contribute. |
|
Solved, this is working for me:
|
I have the same problem with using the :id param and PUT/PATCH/POST and Bind(). It only works with version 4.1.6 or older.. |
I'm having this problem with echo v4.1.11. When I have this code: callbackURL := ctx.QueryParam("callback")
payload := echo.Map{}
err := ctx.Bind(&payload) This produces the error:
If I remove the |
Thank you, @vishr. It works for me. |
Same problem here with Echo v4.1.11 month := c.Param("month")
var lines []models.CLinesToUpdate
if err := c.Bind(&lines); err != nil { => binding element must be a struct |
Issue Description
I think a valid use case of binding to a
map[string]interface{}
now causes the following error:Binding element must be a struct
. I think the regression has been caused by #972.Is this use case still valid ?
Checklist
Expected behaviour
Binding a
map[string]interface{}
is valid.Actual behaviour
Binding a
map[string]interface{}
causes an error.Code to debug
Version/commit
1e9845a
The text was updated successfully, but these errors were encountered: