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

Method asRequestOption

codersdk/organizations.go:575–604  ·  view source on GitHub ↗

asRequestOption returns a function that can be used in (*Client).Request. It modifies the request query parameters.

()

Source from the content-addressed store, hash-verified

573// asRequestOption returns a function that can be used in (*Client).Request.
574// It modifies the request query parameters.
575func (f TemplateFilter) asRequestOption() RequestOption {
576 return func(r *http.Request) {
577 var params []string
578 // Make sure all user input is quoted to ensure it's parsed as a single
579 // string.
580 if f.OrganizationID != uuid.Nil {
581 params = append(params, fmt.Sprintf("organization:%q", f.OrganizationID.String()))
582 }
583
584 if f.ExactName != "" {
585 params = append(params, fmt.Sprintf("exact_name:%q", f.ExactName))
586 }
587
588 if f.FuzzyName != "" {
589 params = append(params, fmt.Sprintf("name:%q", f.FuzzyName))
590 }
591
592 if f.AuthorUsername != "" {
593 params = append(params, fmt.Sprintf("author:%q", f.AuthorUsername))
594 }
595
596 if f.SearchQuery != "" {
597 params = append(params, f.SearchQuery)
598 }
599
600 q := r.URL.Query()
601 q.Set("q", strings.Join(params, " "))
602 r.URL.RawQuery = q.Encode()
603 }
604}
605
606// Templates lists all viewable templates
607func (c *Client) Templates(ctx context.Context, filter TemplateFilter) ([]Template, error) {

Callers 1

TemplatesMethod · 0.45

Calls 3

EncodeMethod · 0.80
SetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected