gopkg.in/moby/moby.v1@v1.13.1/client/image_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  // ImageInspectWithRaw returns the image information and its raw representation.
    14  func (cli *Client) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) {
    15  	serverResp, err := cli.get(ctx, "/images/"+imageID+"/json", nil, nil)
    16  	if err != nil {
    17  		if serverResp.statusCode == http.StatusNotFound {
    18  			return types.ImageInspect{}, nil, imageNotFoundError{imageID}
    19  		}
    20  		return types.ImageInspect{}, nil, err
    21  	}
    22  	defer ensureReaderClosed(serverResp)
    23  
    24  	body, err := ioutil.ReadAll(serverResp.body)
    25  	if err != nil {
    26  		return types.ImageInspect{}, nil, err
    27  	}
    28  
    29  	var response types.ImageInspect
    30  	rdr := bytes.NewReader(body)
    31  	err = json.NewDecoder(rdr).Decode(&response)
    32  	return response, body, err
    33  }