Files
moby/client/node_list.go
Poyraz Küçükarslan 44e1ccd0a3 client: add missing doc comments to config, secret, and node types
Add missing Go doc comments to the exported option and result types
in config_remove.go, config_update.go, secret_remove.go,
secret_update.go, node_inspect.go, node_list.go, node_remove.go,
and node_update.go.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Poyraz Küçükarslan <83272398+PoyrazK@users.noreply.github.com>
2026-03-14 11:21:58 +01:00

35 lines
775 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
}
// NodeListResult holds the result of [Client.NodeList].
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
}