mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-21 16:58:08 +08:00
form_mapping.go: rename method name on setter interface, add comments
This commit is contained in:
parent
adff101d26
commit
6c5e1da5ad
@ -72,7 +72,8 @@ var (
|
||||
multipartFileHeaderStructType = reflect.TypeOf(multipart.FileHeader{})
|
||||
)
|
||||
|
||||
func (r *multipartRequest) Set(value reflect.Value, field reflect.StructField, key string, opt setOptions) (isSetted bool, err error) {
|
||||
// TrySet - try to set a value by the multipart request with the binding a form file
|
||||
func (r *multipartRequest) TrySet(value reflect.Value, field reflect.StructField, key string, opt setOptions) (isSetted bool, err error) {
|
||||
if value.Type() == multipartFileHeaderStructType {
|
||||
_, file, err := (*http.Request)(r).FormFile(key)
|
||||
if err != nil {
|
||||
|
@ -33,14 +33,15 @@ func mapFormByTag(ptr interface{}, form map[string][]string, tag string) error {
|
||||
|
||||
// setter - try to set value on a walking by fields of a struct
|
||||
type setter interface {
|
||||
Set(value reflect.Value, field reflect.StructField, key string, opt setOptions) (isSetted bool, err error)
|
||||
TrySet(value reflect.Value, field reflect.StructField, key string, opt setOptions) (isSetted bool, err error)
|
||||
}
|
||||
|
||||
type formSource map[string][]string
|
||||
|
||||
var _ setter = formSource(nil)
|
||||
|
||||
func (form formSource) Set(value reflect.Value, field reflect.StructField, tagValue string, opt setOptions) (isSetted bool, err error) {
|
||||
// TrySet - try to set a value by request's form source (like map[string][]string)
|
||||
func (form formSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt setOptions) (isSetted bool, err error) {
|
||||
return setByForm(value, field, form, tagValue, opt)
|
||||
}
|
||||
|
||||
@ -130,7 +131,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter
|
||||
}
|
||||
}
|
||||
|
||||
return setter.Set(value, field, tagValue, setOpt)
|
||||
return setter.TrySet(value, field, tagValue, setOpt)
|
||||
}
|
||||
|
||||
func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSetted bool, err error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user