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

Function ParseEnum

coderd/httpapi/queryparams.go:344–351  ·  view source on GitHub ↗

ParseEnum is a function that can be passed into ParseCustom that handles enum validation.

(term string)

Source from the content-addressed store, hash-verified

342// ParseEnum is a function that can be passed into ParseCustom that handles enum
343// validation.
344func ParseEnum[T ValidEnum](term string) (T, error) {
345 enum := T(term)
346 if enum.Valid() {
347 return enum, nil
348 }
349 var empty T
350 return empty, xerrors.Errorf("%q is not a valid value", term)
351}
352
353// ParseCustom has to be a function, not a method on QueryParamParser because generics
354// cannot be used on struct methods.

Callers

nothing calls this directly

Calls 2

ValidMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected