1
0
mirror of https://github.com/labstack/echo.git synced 2025-12-01 22:51:17 +02:00

Added feature to map url params to a struct with the default binder (#1165)

* Added feature to map url params to a struct with the default binder

* Added test for mix of POST data and bound params

* Renamed variables

* Added error check

* Removed unneded fix
This commit is contained in:
kolaente
2019-06-21 15:12:55 +02:00
committed by Vishal Rana
parent 31361576e8
commit 858270f6f5
3 changed files with 63 additions and 2 deletions

11
bind.go
View File

@@ -33,6 +33,17 @@ type (
// Bind implements the `Binder#Bind` function.
func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
req := c.Request()
paramNames := c.ParamNames()
paramValues := c.ParamValues()
params := make(map[string][]string)
for i, name := range paramNames {
params[name] = []string{paramValues[i]}
}
if err := b.bindData(i, params, "param"); err != nil {
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
}
if req.ContentLength == 0 {
if req.Method == http.MethodGet || req.Method == http.MethodDelete {
if err = b.bindData(i, c.QueryParams(), "query"); err != nil {