github.com/hms58/moby@v1.13.1/client/task_list.go (about) 1 package client 2 3 import ( 4 "encoding/json" 5 "net/url" 6 7 "github.com/docker/docker/api/types" 8 "github.com/docker/docker/api/types/filters" 9 "github.com/docker/docker/api/types/swarm" 10 "golang.org/x/net/context" 11 ) 12 13 // TaskList returns the list of tasks. 14 func (cli *Client) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) { 15 query := url.Values{} 16 17 if options.Filters.Len() > 0 { 18 filterJSON, err := filters.ToParam(options.Filters) 19 if err != nil { 20 return nil, err 21 } 22 23 query.Set("filters", filterJSON) 24 } 25 26 resp, err := cli.get(ctx, "/tasks", query, nil) 27 if err != nil { 28 return nil, err 29 } 30 31 var tasks []swarm.Task 32 err = json.NewDecoder(resp.body).Decode(&tasks) 33 ensureReaderClosed(resp) 34 return tasks, err 35 }