| 211 | } |
| 212 | |
| 213 | func 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 | |
| 245 | func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSet bool, err error) { |
| 246 | vs, ok := form[tagValue] |