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)
| 83 | // |
| 84 | // See ParseValue for supported types and options |
| 85 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…