github.com/hms58/moby@v1.13.1/client/node_inspect.go (about)

     1  package client
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  	"io/ioutil"
     7  	"net/http"
     8  
     9  	"github.com/docker/docker/api/types/swarm"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  // NodeInspectWithRaw returns the node information.
    14  func (cli *Client) NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) {
    15  	serverResp, err := cli.get(ctx, "/nodes/"+nodeID, nil, nil)
    16  	if err != nil {
    17  		if serverResp.statusCode == http.StatusNotFound {
    18  			return swarm.Node{}, nil, nodeNotFoundError{nodeID}
    19  		}
    20  		return swarm.Node{}, nil, err
    21  	}
    22  	defer ensureReaderClosed(serverResp)
    23  
    24  	body, err := ioutil.ReadAll(serverResp.body)
    25  	if err != nil {
    26  		return swarm.Node{}, nil, err
    27  	}
    28  
    29  	var response swarm.Node
    30  	rdr := bytes.NewReader(body)
    31  	err = json.NewDecoder(rdr).Decode(&response)
    32  	return response, body, err
    33  }