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

Method UUIDorName

coderd/httpapi/queryparams.go:186–194  ·  view source on GitHub ↗

UUIDorName will parse a string as a UUID, if it fails, it uses the "fetchByName" function to return a UUID based on the value as a string. This is useful when fetching something like an organization by ID or by name.

(vals url.Values, def uuid.UUID, queryParam string, fetchByName func(name string) (uuid.UUID, error))

Source from the content-addressed store, hash-verified

184// function to return a UUID based on the value as a string.
185// This is useful when fetching something like an organization by ID or by name.
186func (p *QueryParamParser) UUIDorName(vals url.Values, def uuid.UUID, queryParam string, fetchByName func(name string) (uuid.UUID, error)) uuid.UUID {
187 return ParseCustom(p, vals, def, queryParam, func(v string) (uuid.UUID, error) {
188 id, err := uuid.Parse(v)
189 if err == nil {
190 return id, nil
191 }
192 return fetchByName(v)
193 })
194}
195
196func (p *QueryParamParser) UUIDorMe(vals url.Values, def uuid.UUID, me uuid.UUID, queryParam string) uuid.UUID {
197 return ParseCustom(p, vals, def, queryParam, func(v string) (uuid.UUID, error) {

Callers 1

groupsMethod · 0.95

Calls 2

ParseCustomFunction · 0.85
ParseMethod · 0.65

Tested by

no test coverage detected