volume_list.go 751 B

123456789101112131415161718192021222324252627282930313233
  1. package client
  2. import (
  3. "encoding/json"
  4. "net/url"
  5. "github.com/docker/engine-api/types"
  6. "github.com/docker/engine-api/types/filters"
  7. "golang.org/x/net/context"
  8. )
  9. // VolumeList returns the volumes configured in the docker host.
  10. func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error) {
  11. var volumes types.VolumesListResponse
  12. query := url.Values{}
  13. if filter.Len() > 0 {
  14. filterJSON, err := filters.ToParam(filter)
  15. if err != nil {
  16. return volumes, err
  17. }
  18. query.Set("filters", filterJSON)
  19. }
  20. resp, err := cli.get(ctx, "/volumes", query, nil)
  21. if err != nil {
  22. return volumes, err
  23. }
  24. err = json.NewDecoder(resp.body).Decode(&volumes)
  25. ensureReaderClosed(resp)
  26. return volumes, err
  27. }