github.com/skf/moby@v1.13.1/client/network_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"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  // NetworkInspect returns the information for a specific network configured in the docker host.
    14  func (cli *Client) NetworkInspect(ctx context.Context, networkID string) (types.NetworkResource, error) {
    15  	networkResource, _, err := cli.NetworkInspectWithRaw(ctx, networkID)
    16  	return networkResource, err
    17  }
    18  
    19  // NetworkInspectWithRaw returns the information for a specific network configured in the docker host and its raw representation.
    20  func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string) (types.NetworkResource, []byte, error) {
    21  	var networkResource types.NetworkResource
    22  	resp, err := cli.get(ctx, "/networks/"+networkID, nil, nil)
    23  	if err != nil {
    24  		if resp.statusCode == http.StatusNotFound {
    25  			return networkResource, nil, networkNotFoundError{networkID}
    26  		}
    27  		return networkResource, nil, err
    28  	}
    29  	defer ensureReaderClosed(resp)
    30  
    31  	body, err := ioutil.ReadAll(resp.body)
    32  	if err != nil {
    33  		return networkResource, nil, err
    34  	}
    35  	rdr := bytes.NewReader(body)
    36  	err = json.NewDecoder(rdr).Decode(&networkResource)
    37  	return networkResource, body, err
    38  }