mirror of
https://github.com/moby/moby.git
synced 2026-07-13 02:52:20 +00:00
This moves the type to the api/types/network package, but also introduces a "Summary" alias; the intent here is to allow diverging the types used for "list" and "inspect" operations, as list operations may only be producing a subset of the fields available. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
33 lines
922 B
Go
33 lines
922 B
Go
package client // import "github.com/docker/docker/client"
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/url"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/docker/docker/api/types/network"
|
|
)
|
|
|
|
// NetworkList returns the list of networks configured in the docker host.
|
|
func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
|
|
query := url.Values{}
|
|
if options.Filters.Len() > 0 {
|
|
//nolint:staticcheck // ignore SA1019 for old code
|
|
filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
query.Set("filters", filterJSON)
|
|
}
|
|
var networkResources []network.Summary
|
|
resp, err := cli.get(ctx, "/networks", query, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return networkResources, err
|
|
}
|
|
err = json.NewDecoder(resp.body).Decode(&networkResources)
|
|
return networkResources, err
|
|
}
|