From 4d11ca17d0f73f5bd783f45900118295fdfed46b Mon Sep 17 00:00:00 2001 From: Tomofumi Hayashi Date: Sat, 27 Apr 2019 20:38:39 +0900 Subject: barometer: update DMA's vendoring packages Change-Id: I0578b094f1ecdaed20c906be2ba29d51b8089d7c Signed-off-by: Tomofumi Hayashi --- src/dma/vendor/github.com/labstack/echo/bind.go | 48 ++++++++++++++++--------- 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'src/dma/vendor/github.com/labstack/echo/bind.go') diff --git a/src/dma/vendor/github.com/labstack/echo/bind.go b/src/dma/vendor/github.com/labstack/echo/bind.go index 38e07150..4998e25b 100644 --- a/src/dma/vendor/github.com/labstack/echo/bind.go +++ b/src/dma/vendor/github.com/labstack/echo/bind.go @@ -31,9 +31,9 @@ type ( func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) { req := c.Request() if req.ContentLength == 0 { - if req.Method == GET || req.Method == DELETE { + if req.Method == http.MethodGet || req.Method == http.MethodDelete { if err = b.bindData(i, c.QueryParams(), "query"); err != nil { - return NewHTTPError(http.StatusBadRequest, err.Error()) + return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err) } return } @@ -44,30 +44,32 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) { case strings.HasPrefix(ctype, MIMEApplicationJSON): if err = json.NewDecoder(req.Body).Decode(i); err != nil { if ute, ok := err.(*json.UnmarshalTypeError); ok { - return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unmarshal type error: expected=%v, got=%v, offset=%v", ute.Type, ute.Value, ute.Offset)) + return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unmarshal type error: expected=%v, got=%v, field=%v, offset=%v", ute.Type, ute.Value, ute.Field, ute.Offset)).SetInternal(err) } else if se, ok := err.(*json.SyntaxError); ok { - return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Syntax error: offset=%v, error=%v", se.Offset, se.Error())) + return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Syntax error: offset=%v, error=%v", se.Offset, se.Error())).SetInternal(err) } else { - return NewHTTPError(http.StatusBadRequest, err.Error()) + return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err) } + return NewHTTPError(http.StatusBadRequest, err.Error()) } case strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML): if err = xml.NewDecoder(req.Body).Decode(i); err != nil { if ute, ok := err.(*xml.UnsupportedTypeError); ok { - return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unsupported type error: type=%v, error=%v", ute.Type, ute.Error())) + return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unsupported type error: type=%v, error=%v", ute.Type, ute.Error())).SetInternal(err) } else if se, ok := err.(*xml.SyntaxError); ok { - return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Syntax error: line=%v, error=%v", se.Line, se.Error())) + return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Syntax error: line=%v, error=%v", se.Line, se.Error())).SetInternal(err) } else { - return NewHTTPError(http.StatusBadRequest, err.Error()) + return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err) } + return NewHTTPError(http.StatusBadRequest, err.Error()) } case strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm): params, err := c.FormParams() if err != nil { - return NewHTTPError(http.StatusBadRequest, err.Error()) + return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err) } if err = b.bindData(i, params, "form"); err != nil { - return NewHTTPError(http.StatusBadRequest, err.Error()) + return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err) } default: return ErrUnsupportedMediaType @@ -96,14 +98,29 @@ func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag inputFieldName = typeField.Name // If tag is nil, we inspect if the field is a struct. if _, ok := bindUnmarshaler(structField); !ok && structFieldKind == reflect.Struct { - err := b.bindData(structField.Addr().Interface(), data, tag) - if err != nil { + if err := b.bindData(structField.Addr().Interface(), data, tag); err != nil { return err } continue } } + inputValue, exists := data[inputFieldName] + if !exists { + // Go json.Unmarshal supports case insensitive binding. However the + // url params are bound case sensitive which is inconsistent. To + // fix this we must check all of the map values in a + // case-insensitive search. + inputFieldName = strings.ToLower(inputFieldName) + for k, v := range data { + if strings.ToLower(k) == inputFieldName { + inputValue = v + exists = true + break + } + } + } + if !exists { continue } @@ -126,10 +143,9 @@ func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag } } val.Field(i).Set(slice) - } else { - if err := setWithProperType(typeField.Type.Kind(), inputValue[0], structField); err != nil { - return err - } + } else if err := setWithProperType(typeField.Type.Kind(), inputValue[0], structField); err != nil { + return err + } } return nil -- cgit 1.2.3-korg