github.com/hms58/moby@v1.13.1/client/volume_inspect.go (about) 1 package client 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "io/ioutil" 7 "net/http" 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 var volume types.Volume 22 resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil) 23 if err != nil { 24 if resp.statusCode == http.StatusNotFound { 25 return volume, nil, volumeNotFoundError{volumeID} 26 } 27 return volume, nil, err 28 } 29 defer ensureReaderClosed(resp) 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 }