github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/client/network_inspect.go (about)

     1  package client
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  	"io/ioutil"
     7  	"net/url"
     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, options types.NetworkInspectOptions) (types.NetworkResource, error) {
    15  	networkResource, _, err := cli.NetworkInspectWithRaw(ctx, networkID, options)
    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, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
    21  	var (
    22  		networkResource types.NetworkResource
    23  		resp            serverResponse
    24  		err             error
    25  	)
    26  	query := url.Values{}
    27  	if options.Verbose {
    28  		query.Set("verbose", "true")
    29  	}
    30  	if options.Scope != "" {
    31  		query.Set("scope", options.Scope)
    32  	}
    33  	resp, err = cli.get(ctx, "/networks/"+networkID, query, nil)
    34  	if err != nil {
    35  		return networkResource, nil, wrapResponseError(err, resp, "network", networkID)
    36  	}
    37  	defer ensureReaderClosed(resp)
    38  
    39  	body, err := ioutil.ReadAll(resp.body)
    40  	if err != nil {
    41  		return networkResource, nil, err
    42  	}
    43  	rdr := bytes.NewReader(body)
    44  	err = json.NewDecoder(rdr).Decode(&networkResource)
    45  	return networkResource, body, err
    46  }