asRequestOption returns a function that can be used in (*Client).Request. It modifies the request query parameters.
()
| 537 | // asRequestOption returns a function that can be used in (*Client).Request. |
| 538 | // It modifies the request query parameters. |
| 539 | func (f WorkspaceFilter) asRequestOption() RequestOption { |
| 540 | return func(r *http.Request) { |
| 541 | var params []string |
| 542 | // Make sure all user input is quoted to ensure it's parsed as a single |
| 543 | // string. |
| 544 | if f.Owner != "" { |
| 545 | params = append(params, fmt.Sprintf("owner:%q", f.Owner)) |
| 546 | } |
| 547 | if f.Name != "" { |
| 548 | params = append(params, fmt.Sprintf("name:%q", f.Name)) |
| 549 | } |
| 550 | if f.Template != "" { |
| 551 | params = append(params, fmt.Sprintf("template:%q", f.Template)) |
| 552 | } |
| 553 | if f.Status != "" { |
| 554 | params = append(params, fmt.Sprintf("status:%q", f.Status)) |
| 555 | } |
| 556 | if f.Shared != nil { |
| 557 | params = append(params, fmt.Sprintf("shared:%v", *f.Shared)) |
| 558 | } |
| 559 | if f.SharedWithUser != "" { |
| 560 | params = append(params, fmt.Sprintf("shared_with_user:%q", f.SharedWithUser)) |
| 561 | } |
| 562 | if f.SharedWithGroup != "" { |
| 563 | params = append(params, fmt.Sprintf("shared_with_group:%q", f.SharedWithGroup)) |
| 564 | } |
| 565 | if f.FilterQuery != "" { |
| 566 | // If custom stuff is added, just add it on here. |
| 567 | params = append(params, f.FilterQuery) |
| 568 | } |
| 569 | |
| 570 | q := r.URL.Query() |
| 571 | q.Set("q", strings.Join(params, " ")) |
| 572 | r.URL.RawQuery = q.Encode() |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | // Workspaces returns all workspaces the authenticated user has access to. |
| 577 | func (c *Client) Workspaces(ctx context.Context, filter WorkspaceFilter) (WorkspacesResponse, error) { |
no test coverage detected