github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/client/plugin_list.go (about)

     1  package client // import "github.com/docker/docker/client"
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"net/url"
     7  
     8  	"github.com/docker/docker/api/types"
     9  	"github.com/docker/docker/api/types/filters"
    10  )
    11  
    12  // PluginList returns the installed plugins
    13  func (cli *Client) PluginList(ctx context.Context, filter filters.Args) (types.PluginsListResponse, error) {
    14  	var plugins types.PluginsListResponse
    15  	query := url.Values{}
    16  
    17  	if filter.Len() > 0 {
    18  		filterJSON, err := filters.ToParamWithVersion(cli.version, filter)
    19  		if err != nil {
    20  			return plugins, err
    21  		}
    22  		query.Set("filters", filterJSON)
    23  	}
    24  	resp, err := cli.get(ctx, "/plugins", query, nil)
    25  	if err != nil {
    26  		return plugins, wrapResponseError(err, resp, "plugin", "")
    27  	}
    28  
    29  	err = json.NewDecoder(resp.body).Decode(&plugins)
    30  	ensureReaderClosed(resp)
    31  	return plugins, err
    32  }