github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/client/plugin_inspect.go (about)

     1  package client // import "github.com/Prakhar-Agarwal-byte/moby/client"
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"encoding/json"
     7  	"io"
     8  
     9  	"github.com/Prakhar-Agarwal-byte/moby/api/types"
    10  )
    11  
    12  // PluginInspectWithRaw inspects an existing plugin
    13  func (cli *Client) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) {
    14  	if name == "" {
    15  		return nil, nil, objectNotFoundError{object: "plugin", id: name}
    16  	}
    17  	resp, err := cli.get(ctx, "/plugins/"+name+"/json", nil, nil)
    18  	defer ensureReaderClosed(resp)
    19  	if err != nil {
    20  		return nil, nil, err
    21  	}
    22  
    23  	body, err := io.ReadAll(resp.body)
    24  	if err != nil {
    25  		return nil, nil, err
    26  	}
    27  	var p types.Plugin
    28  	rdr := bytes.NewReader(body)
    29  	err = json.NewDecoder(rdr).Decode(&p)
    30  	return &p, body, err
    31  }