@@ -49,10 +49,11 @@ const (
4949// It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found.
5050//
5151// Empty String Handling:
52- // If the parameter exists but has an empty value, the zero value of type T is returned
53- // with no error. For example, a path parameter with value "" returns (0, nil) for int types.
54- // This differs from standard library behavior where parsing empty strings returns errors.
55- // To treat empty values as errors, validate the result separately or check the raw value.
52+ //
53+ // If the parameter exists but has an empty value, the zero value of type T is returned
54+ // with no error. For example, a path parameter with value "" returns (0, nil) for int types.
55+ // This differs from standard library behavior where parsing empty strings returns errors.
56+ // To treat empty values as errors, validate the result separately or check the raw value.
5657//
5758// See ParseValue for supported types and options
5859func PathParam [T any ](c * Context , paramName string , opts ... any ) (T , error ) {
@@ -74,10 +75,11 @@ func PathParam[T any](c *Context, paramName string, opts ...any) (T, error) {
7475// Returns an error only if parsing fails (e.g., "abc" for int type).
7576//
7677// Example:
77- // id, err := echo.PathParamOr[int](c, "id", 0)
78- // // If "id" is missing: returns (0, nil)
79- // // If "id" is "123": returns (123, nil)
80- // // If "id" is "abc": returns (0, BindingError)
78+ //
79+ // id, err := echo.PathParamOr[int](c, "id", 0)
80+ // // If "id" is missing: returns (0, nil)
81+ // // If "id" is "123": returns (123, nil)
82+ // // If "id" is "abc": returns (0, BindingError)
8183//
8284// See ParseValue for supported types and options
8385func PathParamOr [T any ](c * Context , paramName string , defaultValue T , opts ... any ) (T , error ) {
@@ -97,10 +99,11 @@ func PathParamOr[T any](c *Context, paramName string, defaultValue T, opts ...an
9799// It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found.
98100//
99101// Empty String Handling:
100- // If the parameter exists but has an empty value (?key=), the zero value of type T is returned
101- // with no error. For example, "?count=" returns (0, nil) for int types.
102- // This differs from standard library behavior where parsing empty strings returns errors.
103- // To treat empty values as errors, validate the result separately or check the raw value.
102+ //
103+ // If the parameter exists but has an empty value (?key=), the zero value of type T is returned
104+ // with no error. For example, "?count=" returns (0, nil) for int types.
105+ // This differs from standard library behavior where parsing empty strings returns errors.
106+ // To treat empty values as errors, validate the result separately or check the raw value.
104107//
105108// Behavior Summary:
106109// - Missing key (?other=value): returns (zero, ErrNonExistentKey)
@@ -131,10 +134,11 @@ func QueryParam[T any](c *Context, key string, opts ...any) (T, error) {
131134// Returns an error only if parsing fails (e.g., "abc" for int type).
132135//
133136// Example:
134- // page, err := echo.QueryParamOr[int](c, "page", 1)
135- // // If "page" is missing: returns (1, nil)
136- // // If "page" is "5": returns (5, nil)
137- // // If "page" is "abc": returns (1, BindingError)
137+ //
138+ // page, err := echo.QueryParamOr[int](c, "page", 1)
139+ // // If "page" is missing: returns (1, nil)
140+ // // If "page" is "5": returns (5, nil)
141+ // // If "page" is "abc": returns (1, BindingError)
138142//
139143// See ParseValue for supported types and options
140144func QueryParamOr [T any ](c * Context , key string , defaultValue T , opts ... any ) (T , error ) {
@@ -175,10 +179,11 @@ func QueryParams[T any](c *Context, key string, opts ...any) ([]T, error) {
175179// Returns an error only if parsing any value fails.
176180//
177181// Example:
178- // ids, err := echo.QueryParamsOr[int](c, "ids", []int{})
179- // // If "ids" is missing: returns ([], nil)
180- // // If "ids" is "1&ids=2": returns ([1, 2], nil)
181- // // If "ids" contains "abc": returns ([], BindingError)
182+ //
183+ // ids, err := echo.QueryParamsOr[int](c, "ids", []int{})
184+ // // If "ids" is missing: returns ([], nil)
185+ // // If "ids" is "1&ids=2": returns ([1, 2], nil)
186+ // // If "ids" contains "abc": returns ([], BindingError)
182187//
183188// See ParseValues for supported types and options
184189func QueryParamsOr [T any ](c * Context , key string , defaultValue []T , opts ... any ) ([]T , error ) {
@@ -198,10 +203,11 @@ func QueryParamsOr[T any](c *Context, key string, defaultValue []T, opts ...any)
198203// It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found.
199204//
200205// Empty String Handling:
201- // If the form field exists but has an empty value, the zero value of type T is returned
202- // with no error. For example, an empty form field returns (0, nil) for int types.
203- // This differs from standard library behavior where parsing empty strings returns errors.
204- // To treat empty values as errors, validate the result separately or check the raw value.
206+ //
207+ // If the form field exists but has an empty value, the zero value of type T is returned
208+ // with no error. For example, an empty form field returns (0, nil) for int types.
209+ // This differs from standard library behavior where parsing empty strings returns errors.
210+ // To treat empty values as errors, validate the result separately or check the raw value.
205211//
206212// See ParseValue for supported types and options
207213func FormValue [T any ](c * Context , key string , opts ... any ) (T , error ) {
@@ -232,10 +238,11 @@ func FormValue[T any](c *Context, key string, opts ...any) (T, error) {
232238// Returns an error only if parsing fails or form parsing errors occur.
233239//
234240// Example:
235- // limit, err := echo.FormValueOr[int](c, "limit", 100)
236- // // If "limit" is missing: returns (100, nil)
237- // // If "limit" is "50": returns (50, nil)
238- // // If "limit" is "abc": returns (100, BindingError)
241+ //
242+ // limit, err := echo.FormValueOr[int](c, "limit", 100)
243+ // // If "limit" is missing: returns (100, nil)
244+ // // If "limit" is "50": returns (50, nil)
245+ // // If "limit" is "abc": returns (100, BindingError)
239246//
240247// See ParseValue for supported types and options
241248func FormValueOr [T any ](c * Context , key string , defaultValue T , opts ... any ) (T , error ) {
@@ -284,9 +291,10 @@ func FormValues[T any](c *Context, key string, opts ...any) ([]T, error) {
284291// Returns an error only if parsing any value fails or form parsing errors occur.
285292//
286293// Example:
287- // tags, err := echo.FormValuesOr[string](c, "tags", []string{})
288- // // If "tags" is missing: returns ([], nil)
289- // // If form parsing fails: returns (nil, error)
294+ //
295+ // tags, err := echo.FormValuesOr[string](c, "tags", []string{})
296+ // // If "tags" is missing: returns ([], nil)
297+ // // If form parsing fails: returns (nil, error)
290298//
291299// See ParseValues for supported types and options
292300func FormValuesOr [T any ](c * Context , key string , defaultValue []T , opts ... any ) ([]T , error ) {
0 commit comments