Home / Function/ trySplit() — gin Function Reference

trySplit() — gin Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  74c77de5_2990_3612_24ae_1118bd5d35ab["trySplit()"]
  0bcba57f_f00e_ed0e_0516_ee30758711c8["form_mapping.go"]
  74c77de5_2990_3612_24ae_1118bd5d35ab -->|defined in| 0bcba57f_f00e_ed0e_0516_ee30758711c8
  a3bc6e41_4537_9cf9_f14c_d1a876a83af1["setByForm()"]
  a3bc6e41_4537_9cf9_f14c_d1a876a83af1 -->|calls| 74c77de5_2990_3612_24ae_1118bd5d35ab
  style 74c77de5_2990_3612_24ae_1118bd5d35ab fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

binding/form_mapping.go lines 213–243

func trySplit(vs []string, field reflect.StructField) (newVs []string, err error) {
	cfTag := field.Tag.Get("collection_format")
	if cfTag == "" || cfTag == "multi" {
		return vs, nil
	}

	var sep string
	switch cfTag {
	case "csv":
		sep = ","
	case "ssv":
		sep = " "
	case "tsv":
		sep = "\t"
	case "pipes":
		sep = "|"
	default:
		return vs, fmt.Errorf("%s is not supported in the collection_format. (multi, csv, ssv, tsv, pipes)", cfTag)
	}

	totalLength := 0
	for _, v := range vs {
		totalLength += strings.Count(v, sep) + 1
	}
	newVs = make([]string, 0, totalLength)
	for _, v := range vs {
		newVs = append(newVs, strings.Split(v, sep)...)
	}

	return newVs, nil
}

Subdomains

Called By

Frequently Asked Questions

What does trySplit() do?
trySplit() is a function in the gin codebase, defined in binding/form_mapping.go.
Where is trySplit() defined?
trySplit() is defined in binding/form_mapping.go at line 213.
What calls trySplit()?
trySplit() is called by 1 function(s): setByForm.

Analyze Your Own Codebase

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

Try Supermodel Free