image_list.go 960 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // ImageList returns a list of images in the docker host.
  10. func (cli *Client) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.Image, error) {
  11. var images []types.Image
  12. query := url.Values{}
  13. if options.Filters.Len() > 0 {
  14. filterJSON, err := filters.ToParam(options.Filters)
  15. if err != nil {
  16. return images, err
  17. }
  18. query.Set("filters", filterJSON)
  19. }
  20. if options.MatchName != "" {
  21. // FIXME rename this parameter, to not be confused with the filters flag
  22. query.Set("filter", options.MatchName)
  23. }
  24. if options.All {
  25. query.Set("all", "1")
  26. }
  27. serverResp, err := cli.get(ctx, "/images/json", query, nil)
  28. if err != nil {
  29. return images, err
  30. }
  31. err = json.NewDecoder(serverResp.body).Decode(&images)
  32. ensureReaderClosed(serverResp)
  33. return images, err
  34. }