MCPcopy
hub / github.com/gin-gonic/gin / trySplit

Function trySplit

binding/form_mapping.go:213–243  ·  view source on GitHub ↗
(vs []string, field reflect.StructField)

Source from the content-addressed store, hash-verified

211}
212
213func trySplit(vs []string, field reflect.StructField) (newVs []string, err error) {
214 cfTag := field.Tag.Get("collection_format")
215 if cfTag == "" || cfTag == "multi" {
216 return vs, nil
217 }
218
219 var sep string
220 switch cfTag {
221 case "csv":
222 sep = ","
223 case "ssv":
224 sep = " "
225 case "tsv":
226 sep = "\t"
227 case "pipes":
228 sep = "|"
229 default:
230 return vs, fmt.Errorf("%s is not supported in the collection_format. (multi, csv, ssv, tsv, pipes)", cfTag)
231 }
232
233 totalLength := 0
234 for _, v := range vs {
235 totalLength += strings.Count(v, sep) + 1
236 }
237 newVs = make([]string, 0, totalLength)
238 for _, v := range vs {
239 newVs = append(newVs, strings.Split(v, sep)...)
240 }
241
242 return newVs, nil
243}
244
245func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSet bool, err error) {
246 vs, ok := form[tagValue]

Callers 1

setByFormFunction · 0.85

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected