setByForm() — gin Function Reference
Architecture documentation for the setByForm() function in form_mapping.go from the gin codebase.
Entity Profile
Dependency Diagram
graph TD a3bc6e41_4537_9cf9_f14c_d1a876a83af1["setByForm()"] 0bcba57f_f00e_ed0e_0516_ee30758711c8["form_mapping.go"] a3bc6e41_4537_9cf9_f14c_d1a876a83af1 -->|defined in| 0bcba57f_f00e_ed0e_0516_ee30758711c8 77fb8e79_5378_81f8_a5e5_43e49056cd67["trySetUsingParser()"] a3bc6e41_4537_9cf9_f14c_d1a876a83af1 -->|calls| 77fb8e79_5378_81f8_a5e5_43e49056cd67 fe1ce612_0a94_5769_acda_dde6219d8c6c["trySetCustom()"] a3bc6e41_4537_9cf9_f14c_d1a876a83af1 -->|calls| fe1ce612_0a94_5769_acda_dde6219d8c6c 74c77de5_2990_3612_24ae_1118bd5d35ab["trySplit()"] a3bc6e41_4537_9cf9_f14c_d1a876a83af1 -->|calls| 74c77de5_2990_3612_24ae_1118bd5d35ab df4a8b35_775f_3b24_ca25_1d1a622d9386["setSlice()"] a3bc6e41_4537_9cf9_f14c_d1a876a83af1 -->|calls| df4a8b35_775f_3b24_ca25_1d1a622d9386 7d109b23_ce35_afaa_2c84_5f028e2f243e["setArray()"] a3bc6e41_4537_9cf9_f14c_d1a876a83af1 -->|calls| 7d109b23_ce35_afaa_2c84_5f028e2f243e 258ae74c_d8fe_39e5_de46_9ff457fed54a["setWithProperType()"] a3bc6e41_4537_9cf9_f14c_d1a876a83af1 -->|calls| 258ae74c_d8fe_39e5_de46_9ff457fed54a style a3bc6e41_4537_9cf9_f14c_d1a876a83af1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
binding/form_mapping.go lines 245–321
func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSet bool, err error) {
vs, ok := form[tagValue]
if !ok && !opt.isDefaultExists {
return false, nil
}
switch value.Kind() {
case reflect.Slice:
if len(vs) == 0 {
if !opt.isDefaultExists {
return false, nil
}
vs = []string{opt.defaultValue}
// pre-process the default value for multi if present
cfTag := field.Tag.Get("collection_format")
if cfTag == "" || cfTag == "multi" {
vs = strings.Split(opt.defaultValue, ",")
}
}
if ok, err = trySetUsingParser(vs[0], value, opt.parser); ok {
return ok, err
} else if ok, err = trySetCustom(vs[0], value); ok {
return ok, err
}
if vs, err = trySplit(vs, field); err != nil {
return false, err
}
return true, setSlice(vs, value, field, opt)
case reflect.Array:
if len(vs) == 0 {
if !opt.isDefaultExists {
return false, nil
}
vs = []string{opt.defaultValue}
// pre-process the default value for multi if present
cfTag := field.Tag.Get("collection_format")
if cfTag == "" || cfTag == "multi" {
vs = strings.Split(opt.defaultValue, ",")
}
}
if ok, err = trySetUsingParser(vs[0], value, opt.parser); ok {
return ok, err
} else if ok, err = trySetCustom(vs[0], value); ok {
return ok, err
}
if vs, err = trySplit(vs, field); err != nil {
return false, 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, opt)
default:
var val string
if !ok || len(vs) == 0 || (len(vs) > 0 && vs[0] == "") {
val = opt.defaultValue
} else if len(vs) > 0 {
val = vs[0]
}
if ok, err = trySetUsingParser(val, value, opt.parser); ok {
return ok, err
} else if ok, err = trySetCustom(val, value); ok {
return ok, err
}
return true, setWithProperType(val, value, field, opt)
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does setByForm() do?
setByForm() is a function in the gin codebase, defined in binding/form_mapping.go.
Where is setByForm() defined?
setByForm() is defined in binding/form_mapping.go at line 245.
What does setByForm() call?
setByForm() calls 6 function(s): setArray, setSlice, setWithProperType, trySetCustom, trySetUsingParser, trySplit.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free