setFormMap error of result

This commit is contained in:
daheige 2021-04-21 23:05:59 +08:00
parent c0418c48e4
commit 39c42871ae

View File

@ -16,7 +16,15 @@ import (
"github.com/gin-gonic/gin/internal/json"
)
var errUnknownType = errors.New("unknown type")
var (
errUnknownType = errors.New("unknown type")
// ErrConvertMapStringSlice covert to map[string][]string
ErrConvertMapStringSlice = errors.New("can not convert to map slices of strings")
// ErrConvertToMapString can not convert to map[string]string
ErrConvertToMapString = errors.New("can not convert to map of strings")
)
func mapUri(ptr interface{}, m map[string][]string) error {
return mapFormByTag(ptr, m, "uri")
@ -371,7 +379,7 @@ func setFormMap(ptr interface{}, form map[string][]string) error {
if el.Kind() == reflect.Slice {
ptrMap, ok := ptr.(map[string][]string)
if !ok {
return errors.New("cannot convert to map slices of strings")
return ErrConvertMapStringSlice
}
for k, v := range form {
ptrMap[k] = v
@ -382,7 +390,7 @@ func setFormMap(ptr interface{}, form map[string][]string) error {
ptrMap, ok := ptr.(map[string]string)
if !ok {
return errors.New("cannot convert to map of strings")
return ErrConvertToMapString
}
for k, v := range form {
ptrMap[k] = v[len(v)-1] // pick last