1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-05 00:58:47 +02:00

Enable case insensitive query param matching

Unmarshalling body params with json.Unmarshal supports case-insensitive
matching against struct tags.  Matching query params case insensitive
provides a more sane and consistent experience for API consumers.

The original url.Values keys remain case sensitive.
This commit is contained in:
Brandon Hansen
2018-05-30 14:50:24 -07:00
committed by Vishal Rana
parent ec7b497940
commit 01cfe83efe
2 changed files with 29 additions and 1 deletions

17
bind.go
View File

@ -103,7 +103,22 @@ func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag
continue
}
}
inputValue, exists := data[inputFieldName]
var inputValue []string
var exists bool
// 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
}