ParseCustom has to be a function, not a method on QueryParamParser because generics cannot be used on struct methods.
(parser *QueryParamParser, vals url.Values, def T, queryParam string, parseFunc func(v string) (T, error))
| 353 | // ParseCustom has to be a function, not a method on QueryParamParser because generics |
| 354 | // cannot be used on struct methods. |
| 355 | func ParseCustom[T any](parser *QueryParamParser, vals url.Values, def T, queryParam string, parseFunc func(v string) (T, error)) T { |
| 356 | v, err := parseQueryParam(parser, vals, parseFunc, def, queryParam) |
| 357 | if err != nil { |
| 358 | parser.Errors = append(parser.Errors, codersdk.ValidationError{ |
| 359 | Field: queryParam, |
| 360 | Detail: fmt.Sprintf("Query param %q has invalid value: %s", queryParam, err.Error()), |
| 361 | }) |
| 362 | } |
| 363 | return v |
| 364 | } |
| 365 | |
| 366 | // ParseCustomList is a function that handles csv query params or multiple values |
| 367 | // for a query param. |