github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/volume_list.go (about)

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