Closed
Description
Issue Description
An error occurred when the url variable parameter was used with c.bind(slice)
Checklist
- Dependencies installed
- No typos
- Searched existing issues and docs
Expected behaviour
The binding result is consistent with the fixed url
Actual behaviour
raise error: binding element must be a struct
Steps to reproduce
pass: curl -X POST -H "Content-Type: application/json" -d '[{"id":2333}]' localhost:1323/a
fail: curl -X POST -H "Content-Type: application/json" -d '[{"id":2333}]' localhost:1323/b
Working code to debug
package main
import (
"github.com/labstack/echo/v4"
"net/http"
)
type Test struct {
ID int `json:"id"`
}
func main() {
e := echo.New()
e.POST("/a", handle)
// :name = b
e.POST("/:name", handle) // -> error: binding element must be a struct
e.Logger.Fatal(e.Start(":1323"))
}
func handle(c echo.Context) error {
var m []*Test
if err := c.Bind(&m); err != nil {
return c.JSON(http.StatusBadRequest, echo.Map{"error": err})
}
return c.JSON(http.StatusOK, m)
}
Version/commit
github.com/labstack/echo/v4 v4.1.17
Metadata
Metadata
Assignees
Labels
No labels