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

Function QueryParamsOr

binder_generic.go:189–200  ·  view source on GitHub ↗

QueryParamsOr extracts and parses all values for a query parameter key as a slice. Returns defaultValue if the parameter is not found. Returns an error only if parsing any value fails. Example: ids, err := echo.QueryParamsOr[int](c, "ids", []int{}) // If "ids" is missing: returns ([], nil) // I

(c *Context, key string, defaultValue []T, opts ...any)

Source from the content-addressed store, hash-verified

187//
188// See ParseValues for supported types and options
189func QueryParamsOr[T any](c *Context, key string, defaultValue []T, opts ...any) ([]T, error) {
190 values, ok := c.QueryParams()[key]
191 if !ok {
192 return defaultValue, nil
193 }
194
195 result, err := ParseValuesOr[T](values, defaultValue, opts...)
196 if err != nil {
197 return nil, NewBindingError(key, values, "query params", err)
198 }
199 return result, nil
200}
201
202// FormValue extracts and parses a single form value from the request by key.
203// 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
QueryParamsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…