Home / Function/ mapping() — gin Function Reference

mapping() — gin Function Reference

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

Function go DataBinding Validators calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  ba99b96b_284d_628b_fac7_e9a63aea5c91["mapping()"]
  cf9312e5_ab36_93e2_37fc_2b247a7db964["mappingByPtr()"]
  cf9312e5_ab36_93e2_37fc_2b247a7db964 -->|calls| ba99b96b_284d_628b_fac7_e9a63aea5c91
  be2f0281_158f_19d5_81a3_7906a21c7875["tryToSetValue()"]
  ba99b96b_284d_628b_fac7_e9a63aea5c91 -->|calls| be2f0281_158f_19d5_81a3_7906a21c7875
  style ba99b96b_284d_628b_fac7_e9a63aea5c91 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

binding/form_mapping.go lines 84–136

func mapping(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) {
	if field.Tag.Get(tag) == "-" { // just ignoring this field
		return false, nil
	}

	vKind := value.Kind()

	if vKind == reflect.Ptr {
		var isNew bool
		vPtr := value
		if value.IsNil() {
			isNew = true
			vPtr = reflect.New(value.Type().Elem())
		}
		isSet, err := mapping(vPtr.Elem(), field, setter, tag)
		if err != nil {
			return false, err
		}
		if isNew && isSet {
			value.Set(vPtr)
		}
		return isSet, nil
	}

	if vKind != reflect.Struct || !field.Anonymous {
		ok, err := tryToSetValue(value, field, setter, tag)
		if err != nil {
			return false, err
		}
		if ok {
			return true, nil
		}
	}

	if vKind == reflect.Struct {
		tValue := value.Type()

		var isSet bool
		for i := range value.NumField() {
			sf := tValue.Field(i)
			if sf.PkgPath != "" && !sf.Anonymous { // unexported
				continue
			}
			ok, err := mapping(value.Field(i), sf, setter, tag)
			if err != nil {
				return false, err
			}
			isSet = isSet || ok
		}
		return isSet, nil
	}
	return false, nil
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does mapping() do?
mapping() is a function in the gin codebase.
What does mapping() call?
mapping() calls 1 function(s): tryToSetValue.
What calls mapping()?
mapping() is called by 1 function(s): mappingByPtr.

Analyze Your Own Codebase

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

Try Supermodel Free