github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/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" 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 := io.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 }