mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
Move them together, as we did for most of the other options. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
34 lines
718 B
Go
34 lines
718 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/url"
|
|
|
|
"github.com/moby/moby/api/types/swarm"
|
|
)
|
|
|
|
// NodeListOptions holds parameters to list nodes with.
|
|
type NodeListOptions struct {
|
|
Filters Filters
|
|
}
|
|
|
|
type NodeListResult struct {
|
|
Items []swarm.Node
|
|
}
|
|
|
|
// NodeList returns the list of nodes.
|
|
func (cli *Client) NodeList(ctx context.Context, options NodeListOptions) (NodeListResult, error) {
|
|
query := url.Values{}
|
|
options.Filters.updateURLValues(query)
|
|
resp, err := cli.get(ctx, "/nodes", query, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return NodeListResult{}, err
|
|
}
|
|
|
|
var nodes []swarm.Node
|
|
err = json.NewDecoder(resp.Body).Decode(&nodes)
|
|
return NodeListResult{Items: nodes}, err
|
|
}
|