mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: don't return 200 for deleted workspaces (#1556)
This commit is contained in:
@@ -36,6 +36,14 @@ type Client struct {
|
||||
|
||||
type requestOption func(*http.Request)
|
||||
|
||||
func queryParam(k, v string) requestOption {
|
||||
return func(r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
q.Set(k, v)
|
||||
r.URL.RawQuery = q.Encode()
|
||||
}
|
||||
}
|
||||
|
||||
// Request performs an HTTP request with the body provided.
|
||||
// The caller is responsible for closing the response body.
|
||||
func (c *Client) Request(ctx context.Context, method, path string, body interface{}, opts ...requestOption) (*http.Response, error) {
|
||||
|
||||
+10
-1
@@ -42,7 +42,16 @@ type CreateWorkspaceBuildRequest struct {
|
||||
|
||||
// Workspace returns a single workspace.
|
||||
func (c *Client) Workspace(ctx context.Context, id uuid.UUID) (Workspace, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/workspaces/%s", id), nil)
|
||||
return c.getWorkspace(ctx, id)
|
||||
}
|
||||
|
||||
// DeletedWorkspace returns a single workspace that was deleted.
|
||||
func (c *Client) DeletedWorkspace(ctx context.Context, id uuid.UUID) (Workspace, error) {
|
||||
return c.getWorkspace(ctx, id, queryParam("deleted", "true"))
|
||||
}
|
||||
|
||||
func (c *Client) getWorkspace(ctx context.Context, id uuid.UUID, opts ...requestOption) (Workspace, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/workspaces/%s", id), nil, opts...)
|
||||
if err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user