Files
moby/client/node_list.go
Paweł Gronowski 7ceea4148a client/node: Wrap options and output
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-10-22 12:02:05 +02:00

29 lines
612 B
Go

package client
import (
"context"
"encoding/json"
"net/url"
"github.com/moby/moby/api/types/swarm"
)
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
}