github.com/rawahars/moby@v24.0.4+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"
     8  
     9  	"github.com/docker/docker/api/types/volume"
    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) (volume.Volume, error) {
    14  	vol, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
    15  	return vol, 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) (volume.Volume, []byte, error) {
    20  	if volumeID == "" {
    21  		return volume.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID}
    22  	}
    23  
    24  	var vol volume.Volume
    25  	resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil)
    26  	defer ensureReaderClosed(resp)
    27  	if err != nil {
    28  		return vol, nil, err
    29  	}
    30  
    31  	body, err := io.ReadAll(resp.body)
    32  	if err != nil {
    33  		return vol, nil, err
    34  	}
    35  	rdr := bytes.NewReader(body)
    36  	err = json.NewDecoder(rdr).Decode(&vol)
    37  	return vol, body, err
    38  }