plugin_inspect.go 736 B

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