summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/v4/bind.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/bind.go')
-rw-r--r--vendor/github.com/labstack/echo/v4/bind.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/vendor/github.com/labstack/echo/v4/bind.go b/vendor/github.com/labstack/echo/v4/bind.go
index 07d8034c..959a314c 100644
--- a/vendor/github.com/labstack/echo/v4/bind.go
+++ b/vendor/github.com/labstack/echo/v4/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()
+
+ names := c.ParamNames()
+ values := c.ParamValues()
+ params := map[string][]string{}
+ for i, name := range names {
+ params[name] = []string{values[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 {
@@ -77,9 +88,19 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
}
func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag string) error {
+ if ptr == nil || len(data) == 0 {
+ return nil
+ }
typ := reflect.TypeOf(ptr).Elem()
val := reflect.ValueOf(ptr).Elem()
+ if m, ok := ptr.(*map[string]interface{}); ok {
+ for k, v := range data {
+ (*m)[k] = v[0]
+ }
+ return nil
+ }
+
if typ.Kind() != reflect.Struct {
return errors.New("binding element must be a struct")
}