feat(form): add custom string slice for form tag unmarshal (#3970) (#3971)

Co-authored-by: Bruce Lee <admin@ifocusad.com>
This commit is contained in:
bruceNu1l
2024-05-23 10:16:11 +08:00
committed by GitHub
parent e0d46ded6c
commit 24d67647cb
2 changed files with 98 additions and 0 deletions

View File

@ -193,14 +193,25 @@ func setByForm(value reflect.Value, field reflect.StructField, form map[string][
if !ok {
vs = []string{opt.defaultValue}
}
if ok, err = trySetCustom(vs[0], value); ok {
return ok, err
}
return true, setSlice(vs, value, field)
case reflect.Array:
if !ok {
vs = []string{opt.defaultValue}
}
if ok, err = trySetCustom(vs[0], value); ok {
return ok, err
}
if len(vs) != value.Len() {
return false, fmt.Errorf("%q is not valid value for %s", vs, value.Type().String())
}
return true, setArray(vs, value, field)
default:
var val string