asRequestOption returns a function that can be used in (*Client).Request. It modifies the request query parameters.
()
| 573 | // asRequestOption returns a function that can be used in (*Client).Request. |
| 574 | // It modifies the request query parameters. |
| 575 | func (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 |
| 607 | func (c *Client) Templates(ctx context.Context, filter TemplateFilter) ([]Template, error) { |