TaskByID fetches a single task by its ID. Only tasks owned by codersdk.Me are supported.
(ctx context.Context, id uuid.UUID)
| 202 | // TaskByID fetches a single task by its ID. |
| 203 | // Only tasks owned by codersdk.Me are supported. |
| 204 | func (c *Client) TaskByID(ctx context.Context, id uuid.UUID) (Task, error) { |
| 205 | res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/tasks/%s/%s", "me", id.String()), nil) |
| 206 | if err != nil { |
| 207 | return Task{}, err |
| 208 | } |
| 209 | defer res.Body.Close() |
| 210 | if res.StatusCode != http.StatusOK { |
| 211 | return Task{}, ReadBodyAsError(res) |
| 212 | } |
| 213 | |
| 214 | var task Task |
| 215 | if err := json.NewDecoder(res.Body).Decode(&task); err != nil { |
| 216 | return Task{}, err |
| 217 | } |
| 218 | |
| 219 | return task, nil |
| 220 | } |
| 221 | |
| 222 | // TaskByOwnerAndName fetches a single task by its owner and name. |
| 223 | func (c *Client) TaskByOwnerAndName(ctx context.Context, owner, ident string) (Task, error) { |