| 430 | } |
| 431 | |
| 432 | func (b *ValueBinder) bindWithDelimiter(sourceParam string, dest any, delimiter string, valueMustExist bool) *ValueBinder { |
| 433 | if b.failFast && b.errors != nil { |
| 434 | return b |
| 435 | } |
| 436 | values := b.ValuesFunc(sourceParam) |
| 437 | if len(values) == 0 { |
| 438 | if valueMustExist { |
| 439 | b.setError(b.ErrorFunc(sourceParam, []string{}, "required field value is empty", nil)) |
| 440 | } |
| 441 | return b |
| 442 | } |
| 443 | tmpValues := make([]string, 0, len(values)) |
| 444 | for _, v := range values { |
| 445 | tmpValues = append(tmpValues, strings.Split(v, delimiter)...) |
| 446 | } |
| 447 | |
| 448 | switch d := dest.(type) { |
| 449 | case *[]string: |
| 450 | *d = tmpValues |
| 451 | return b |
| 452 | case *[]bool: |
| 453 | return b.bools(sourceParam, tmpValues, d) |
| 454 | case *[]int64, *[]int32, *[]int16, *[]int8, *[]int: |
| 455 | return b.ints(sourceParam, tmpValues, d) |
| 456 | case *[]uint64, *[]uint32, *[]uint16, *[]uint8, *[]uint: // *[]byte is same as *[]uint8 |
| 457 | return b.uints(sourceParam, tmpValues, d) |
| 458 | case *[]float64, *[]float32: |
| 459 | return b.floats(sourceParam, tmpValues, d) |
| 460 | case *[]time.Duration: |
| 461 | return b.durations(sourceParam, tmpValues, d) |
| 462 | default: |
| 463 | // support only cases when destination is slice |
| 464 | // does not support time.Time as it needs argument (layout) for parsing or BindUnmarshaler |
| 465 | b.setError(b.ErrorFunc(sourceParam, []string{}, "unsupported bind type", nil)) |
| 466 | return b |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | // Int64 binds parameter to int64 variable |
| 471 | func (b *ValueBinder) Int64(sourceParam string, dest *int64) *ValueBinder { |