github.com/docker/Engine@v17.12.1-ce-rc2+incompatible/client/volume_inspect.go (about) 1 package client 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "io/ioutil" 7 "path" 8 9 "github.com/docker/docker/api/types" 10 "golang.org/x/net/context" 11 ) 12 13 // VolumeInspect returns the information about a specific volume in the docker host. 14 func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) { 15 volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID) 16 return volume, err 17 } 18 19 // VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation 20 func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) { 21 // The empty ID needs to be handled here because with an empty ID the 22 // request url will not contain a trailing / which calls the volume list API 23 // instead of volume inspect 24 if volumeID == "" { 25 return types.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID} 26 } 27 28 var volume types.Volume 29 resp, err := cli.get(ctx, path.Join("/volumes", volumeID), nil, nil) 30 if err != nil { 31 return volume, nil, wrapResponseError(err, resp, "volume", volumeID) 32 } 33 defer ensureReaderClosed(resp) 34 35 body, err := ioutil.ReadAll(resp.body) 36 if err != nil { 37 return volume, nil, err 38 } 39 rdr := bytes.NewReader(body) 40 err = json.NewDecoder(rdr).Decode(&volume) 41 return volume, body, err 42 }