mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
29 lines
730 B
Go
29 lines
730 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/url"
|
|
|
|
"github.com/moby/moby/api/types/network"
|
|
)
|
|
|
|
// NetworkListResult holds the result from the [Client.NetworkList] method.
|
|
type NetworkListResult struct {
|
|
Items []network.Summary
|
|
}
|
|
|
|
// NetworkList returns the list of networks configured in the docker host.
|
|
func (cli *Client) NetworkList(ctx context.Context, options NetworkListOptions) (NetworkListResult, error) {
|
|
query := url.Values{}
|
|
options.Filters.updateURLValues(query)
|
|
resp, err := cli.get(ctx, "/networks", query, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return NetworkListResult{}, err
|
|
}
|
|
var res NetworkListResult
|
|
err = json.NewDecoder(resp.Body).Decode(&res.Items)
|
|
return res, err
|
|
}
|