github.com/olljanat/moby@v1.13.1/client/plugin_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  // PluginInspectWithRaw inspects an existing plugin
    14  func (cli *Client) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) {
    15  	resp, err := cli.get(ctx, "/plugins/"+name+"/json", nil, nil)
    16  	if err != nil {
    17  		if resp.statusCode == http.StatusNotFound {
    18  			return nil, nil, pluginNotFoundError{name}
    19  		}
    20  		return nil, nil, err
    21  	}
    22  
    23  	defer ensureReaderClosed(resp)
    24  	body, err := ioutil.ReadAll(resp.body)
    25  	if err != nil {
    26  		return nil, nil, err
    27  	}
    28  	var p types.Plugin
    29  	rdr := bytes.NewReader(body)
    30  	err = json.NewDecoder(rdr).Decode(&p)
    31  	return &p, body, err
    32  }