MCPcopy Index your code
hub / github.com/labstack/echo / bindWithDelimiter

Method bindWithDelimiter

binder.go:432–468  ·  view source on GitHub ↗
(sourceParam string, dest any, delimiter string, valueMustExist bool)

Source from the content-addressed store, hash-verified

430}
431
432func (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
471func (b *ValueBinder) Int64(sourceParam string, dest *int64) *ValueBinder {

Callers 2

BindWithDelimiterMethod · 0.95
MustBindWithDelimiterMethod · 0.95

Calls 6

setErrorMethod · 0.95
boolsMethod · 0.95
intsMethod · 0.95
uintsMethod · 0.95
floatsMethod · 0.95
durationsMethod · 0.95

Tested by

no test coverage detected