MCPcopy
hub / github.com/labstack/echo / PathParamOr

Function PathParamOr

binder_generic.go:85–96  ·  view source on GitHub ↗

PathParamOr extracts and parses a path parameter from the context by name. Returns defaultValue if the parameter is not found or has an empty value. Returns an error only if parsing fails (e.g., "abc" for int type). Example: id, err := echo.PathParamOr[int](c, "id", 0) // If "id" is missing: ret

(c *Context, paramName string, defaultValue T, opts ...any)

Source from the content-addressed store, hash-verified

83//
84// See ParseValue for supported types and options
85func PathParamOr[T any](c *Context, paramName string, defaultValue T, opts ...any) (T, error) {
86 for _, pv := range c.PathValues() {
87 if pv.Name == paramName {
88 v, err := ParseValueOr[T](pv.Value, defaultValue, opts...)
89 if err != nil {
90 return v, NewBindingError(paramName, []string{pv.Value}, "path value", err)
91 }
92 return v, nil
93 }
94 }
95 return defaultValue, nil
96}
97
98// QueryParam extracts and parses a single query parameter from the request by key.
99// It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found.

Callers

nothing calls this directly

Calls 2

NewBindingErrorFunction · 0.85
PathValuesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…