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

Function PathParam

binder_generic.go:59–71  ·  view source on GitHub ↗

PathParam extracts and parses a path parameter from the context by name. It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found. Empty String Handling: If the parameter exists but has an empty value, the zero value of type T is returned with no

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

Source from the content-addressed store, hash-verified

57//
58// See ParseValue for supported types and options
59func PathParam[T any](c *Context, paramName string, opts ...any) (T, error) {
60 for _, pv := range c.PathValues() {
61 if pv.Name == paramName {
62 v, err := ParseValue[T](pv.Value, opts...)
63 if err != nil {
64 return v, NewBindingError(paramName, []string{pv.Value}, "path value", err)
65 }
66 return v, nil
67 }
68 }
69 var zero T
70 return zero, ErrNonExistentKey
71}
72
73// PathParamOr extracts and parses a path parameter from the context by name.
74// Returns defaultValue if the parameter is not found or has an empty value.

Callers 1

Calls 2

NewBindingErrorFunction · 0.85
PathValuesMethod · 0.80

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…