client/node: Wrap options and output

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-10-22 12:01:37 +02:00
parent 25c509b026
commit 7ceea4148a
22 changed files with 145 additions and 76 deletions

View File

@@ -8,17 +8,21 @@ import (
"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) ([]swarm.Node, error) {
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 nil, err
return NodeListResult{}, err
}
var nodes []swarm.Node
err = json.NewDecoder(resp.Body).Decode(&nodes)
return nodes, err
return NodeListResult{Items: nodes}, err
}