github.com/rhatdan/docker@v0.7.7-0.20180119204836-47a0dcbcd20a/client/network_list.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/url"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/filters"
     9  	"golang.org/x/net/context"
    10  )
    11  
    12  // NetworkList returns the list of networks configured in the docker host.
    13  func (cli *Client) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
    14  	query := url.Values{}
    15  	if options.Filters.Len() > 0 {
    16  		filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters)
    17  		if err != nil {
    18  			return nil, err
    19  		}
    20  
    21  		query.Set("filters", filterJSON)
    22  	}
    23  	var networkResources []types.NetworkResource
    24  	resp, err := cli.get(ctx, "/networks", query, nil)
    25  	if err != nil {
    26  		return networkResources, err
    27  	}
    28  	err = json.NewDecoder(resp.body).Decode(&networkResources)
    29  	ensureReaderClosed(resp)
    30  	return networkResources, err
    31  }