github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/client/volume_inspect.go (about)

     1  package client // import "github.com/docker/docker/client"
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"encoding/json"
     7  	"io/ioutil"
     8  
     9  	"github.com/docker/docker/api/types"
    10  )
    11  
    12  // VolumeInspect returns the information about a specific volume in the docker host.
    13  func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) {
    14  	volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
    15  	return volume, err
    16  }
    17  
    18  // VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation
    19  func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) {
    20  	if volumeID == "" {
    21  		return types.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID}
    22  	}
    23  
    24  	var volume types.Volume
    25  	resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil)
    26  	defer ensureReaderClosed(resp)
    27  	if err != nil {
    28  		return volume, nil, wrapResponseError(err, resp, "volume", volumeID)
    29  	}
    30  
    31  	body, err := ioutil.ReadAll(resp.body)
    32  	if err != nil {
    33  		return volume, nil, err
    34  	}
    35  	rdr := bytes.NewReader(body)
    36  	err = json.NewDecoder(rdr).Decode(&volume)
    37  	return volume, body, err
    38  }