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

Method asRequestOption

codersdk/workspaces.go:539–574  ·  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

537// asRequestOption returns a function that can be used in (*Client).Request.
538// It modifies the request query parameters.
539func (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.
577func (c *Client) Workspaces(ctx context.Context, filter WorkspaceFilter) (WorkspacesResponse, error) {

Callers 2

WorkspaceBuildsMethod · 0.45
WorkspacesMethod · 0.45

Calls 2

EncodeMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected