-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Expand file tree
/
Copy pathtask_list.go
More file actions
36 lines (28 loc) · 784 Bytes
/
task_list.go
File metadata and controls
36 lines (28 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package client
import (
"context"
"encoding/json"
"net/url"
"github.com/moby/moby/api/types/swarm"
)
// TaskListOptions holds parameters to list tasks with.
type TaskListOptions struct {
Filters Filters
}
// TaskListResult contains the result of a task list operation.
type TaskListResult struct {
Items []swarm.Task
}
// TaskList returns the list of tasks.
func (cli *Client) TaskList(ctx context.Context, options TaskListOptions) (TaskListResult, error) {
query := url.Values{}
options.Filters.updateURLValues(query)
resp, err := cli.get(ctx, "/tasks", query, nil)
defer ensureReaderClosed(resp)
if err != nil {
return TaskListResult{}, err
}
var tasks []swarm.Task
err = json.NewDecoder(resp.Body).Decode(&tasks)
return TaskListResult{Items: tasks}, err
}