-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Expand file tree
/
Copy pathnode_inspect.go
More file actions
42 lines (35 loc) · 1001 Bytes
/
node_inspect.go
File metadata and controls
42 lines (35 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package client
import (
"bytes"
"context"
"encoding/json"
"io"
"github.com/moby/moby/api/types/swarm"
)
// NodeInspectOptions holds parameters to inspect nodes with.
type NodeInspectOptions struct{}
// NodeInspectResult holds the result of [Client.NodeInspect].
type NodeInspectResult struct {
Node swarm.Node
Raw json.RawMessage
}
// NodeInspect returns the node information.
func (cli *Client) NodeInspect(ctx context.Context, nodeID string, options NodeInspectOptions) (NodeInspectResult, error) {
nodeID, err := trimID("node", nodeID)
if err != nil {
return NodeInspectResult{}, err
}
resp, err := cli.get(ctx, "/nodes/"+nodeID, nil, nil)
defer ensureReaderClosed(resp)
if err != nil {
return NodeInspectResult{}, err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return NodeInspectResult{}, err
}
var response swarm.Node
rdr := bytes.NewReader(body)
err = json.NewDecoder(rdr).Decode(&response)
return NodeInspectResult{Node: response, Raw: body}, err
}