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

Function ParseValueOr

binder_generic.go:393–403  ·  view source on GitHub ↗

ParseValueOr parses value to generic type, when value is empty defaultValue is returned. Types that are supported: - bool - float32 - float64 - int - int8 - int16 - int32 - int64 - uint - uint8/byte - uint16 - uint32 - uint64 - string - echo.BindUnmarshaler interface - encoding.TextUnmarshaler inte

(value string, defaultValue T, opts ...any)

Source from the content-addressed store, hash-verified

391// - time.Duration
392// - time.Time use echo.TimeOpts or echo.TimeLayout to set time parsing configuration
393func ParseValueOr[T any](value string, defaultValue T, opts ...any) (T, error) {
394 if len(value) == 0 {
395 return defaultValue, nil
396 }
397 var tmp T
398 if err := bindValue(value, &tmp, opts...); err != nil {
399 var zero T
400 return zero, fmt.Errorf("failed to parse value, err: %w", err)
401 }
402 return tmp, nil
403}
404
405func bindValue(value string, dest any, opts ...any) error {
406 // NOTE: if this function is ever made public the dest should be checked for nil

Callers 1

ParseValueFunction · 0.85

Calls 1

bindValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…