github.com/olljanat/moby@v1.13.1/client/node_list.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/url"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/filters"
     9  	"github.com/docker/docker/api/types/swarm"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  // NodeList returns the list of nodes.
    14  func (cli *Client) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
    15  	query := url.Values{}
    16  
    17  	if options.Filters.Len() > 0 {
    18  		filterJSON, err := filters.ToParam(options.Filters)
    19  
    20  		if err != nil {
    21  			return nil, err
    22  		}
    23  
    24  		query.Set("filters", filterJSON)
    25  	}
    26  
    27  	resp, err := cli.get(ctx, "/nodes", query, nil)
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  
    32  	var nodes []swarm.Node
    33  	err = json.NewDecoder(resp.body).Decode(&nodes)
    34  	ensureReaderClosed(resp)
    35  	return nodes, err
    36  }