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:
11
bind.go
11
bind.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user