Home / Function/ tryToSetValue() — gin Function Reference

tryToSetValue() — gin Function Reference

Architecture documentation for the tryToSetValue() function in form_mapping.go from the gin codebase.

Function go RequestBinding FormBinding calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  4254e947_60e5_3f50_dde1_ae8d47a783ba["tryToSetValue()"]
  0bcba57f_f00e_ed0e_0516_ee30758711c8["form_mapping.go"]
  4254e947_60e5_3f50_dde1_ae8d47a783ba -->|defined in| 0bcba57f_f00e_ed0e_0516_ee30758711c8
  26bf428b_0733_115a_bf9f_f206c7ab67b2["mapping()"]
  26bf428b_0733_115a_bf9f_f206c7ab67b2 -->|calls| 4254e947_60e5_3f50_dde1_ae8d47a783ba
  50062c3f_d143_b694_2790_c18a9e2cbd88["head()"]
  4254e947_60e5_3f50_dde1_ae8d47a783ba -->|calls| 50062c3f_d143_b694_2790_c18a9e2cbd88
  style 4254e947_60e5_3f50_dde1_ae8d47a783ba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

binding/form_mapping.go lines 145–180

func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) {
	var tagValue string
	var setOpt setOptions

	tagValue = field.Tag.Get(tag)
	tagValue, opts := head(tagValue, ",")

	if tagValue == "" { // default value is FieldName
		tagValue = field.Name
	}
	if tagValue == "" { // when field is "emptyField" variable
		return false, nil
	}

	var opt string
	for len(opts) > 0 {
		opt, opts = head(opts, ",")

		if k, v := head(opt, "="); k == "default" {
			setOpt.isDefaultExists = true
			setOpt.defaultValue = v

			// convert semicolon-separated default values to csv-separated values for processing in setByForm
			if field.Type.Kind() == reflect.Slice || field.Type.Kind() == reflect.Array {
				cfTag := field.Tag.Get("collection_format")
				if cfTag == "" || cfTag == "multi" || cfTag == "csv" {
					setOpt.defaultValue = strings.ReplaceAll(v, ";", ",")
				}
			}
		} else if k, v = head(opt, "="); k == "parser" {
			setOpt.parser = v
		}
	}

	return setter.TrySet(value, field, tagValue, setOpt)
}

Subdomains

Calls

Called By

Frequently Asked Questions

What does tryToSetValue() do?
tryToSetValue() is a function in the gin codebase, defined in binding/form_mapping.go.
Where is tryToSetValue() defined?
tryToSetValue() is defined in binding/form_mapping.go at line 145.
What does tryToSetValue() call?
tryToSetValue() calls 1 function(s): head.
What calls tryToSetValue()?
tryToSetValue() is called by 1 function(s): mapping.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free