podman
37 строк · 912.0 Байт
1package docker
2
3import (
4"context"
5"encoding/json"
6"net/http"
7)
8
9// ListContainersOptions specify parameters to the ListContainers function.
10//
11// See https://goo.gl/kaOHGw for more details.
12type ListContainersOptions struct {
13All bool
14Size bool
15Limit int
16Since string
17Before string
18Filters map[string][]string
19Context context.Context
20}
21
22// ListContainers returns a slice of containers matching the given criteria.
23//
24// See https://goo.gl/kaOHGw for more details.
25func (c *Client) ListContainers(opts ListContainersOptions) ([]APIContainers, error) {
26path := "/containers/json?" + queryString(opts)
27resp, err := c.do(http.MethodGet, path, doOptions{context: opts.Context})
28if err != nil {
29return nil, err
30}
31defer resp.Body.Close()
32var containers []APIContainers
33if err := json.NewDecoder(resp.Body).Decode(&containers); err != nil {
34return nil, err
35}
36return containers, nil
37}
38