MCPcopy Index your code
hub / github.com/coder/coder / parseSingle

Function parseSingle

coderd/httpapi/queryparams.go:431–447  ·  view source on GitHub ↗
(parser *QueryParamParser, parse func(v string) (T, error), def T, queryParam string)

Source from the content-addressed store, hash-verified

429}
430
431func parseSingle[T any](parser *QueryParamParser, parse func(v string) (T, error), def T, queryParam string) func(set []string) (T, error) {
432 return func(set []string) (T, error) {
433 if len(set) > 1 {
434 // Set as a parser.Error rather than return an error.
435 // Returned errors are errors from the passed in `parse` function, and
436 // imply the query param value had attempted to be parsed.
437 // By raising the error this way, we can also more easily control how it
438 // is presented to the user. A returned error is wrapped with more text.
439 parser.Errors = append(parser.Errors, codersdk.ValidationError{
440 Field: queryParam,
441 Detail: fmt.Sprintf("Query param %q provided more than once, found %d times. Only provide 1 instance of this query param.", queryParam, len(set)),
442 })
443 return def, nil
444 }
445 return parse(set[0])
446 }
447}
448
449func parseQueryParamSet[T any](parser *QueryParamParser, vals url.Values, parse func(set []string) (T, error), def T, queryParam string) (T, error) {
450 parser.addParsed(queryParam)

Callers 2

parseNullableQueryParamFunction · 0.85
parseQueryParamFunction · 0.85

Calls 1

parseFunction · 0.50

Tested by

no test coverage detected