Files
moby/client/network_list.go
Sebastiaan van Stijn 485b95600a client: NetworkList: wrap result
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-21 17:40:19 +02:00

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
}