mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
All methods are singular; while pruning will impact multiple items, it's more consistent to use singular for all operations. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
40 lines
1002 B
Go
40 lines
1002 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/moby/moby/api/types/network"
|
|
)
|
|
|
|
// NetworkPruneOptions holds parameters to prune networks.
|
|
type NetworkPruneOptions struct {
|
|
Filters Filters
|
|
}
|
|
|
|
// NetworkPruneResult holds the result from the [Client.NetworkPrune] method.
|
|
type NetworkPruneResult struct {
|
|
Report network.PruneReport
|
|
}
|
|
|
|
// NetworkPrune requests the daemon to delete unused networks
|
|
func (cli *Client) NetworkPrune(ctx context.Context, opts NetworkPruneOptions) (NetworkPruneResult, error) {
|
|
query := url.Values{}
|
|
opts.Filters.updateURLValues(query)
|
|
|
|
resp, err := cli.post(ctx, "/networks/prune", query, nil, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return NetworkPruneResult{}, err
|
|
}
|
|
|
|
var report network.PruneReport
|
|
if err := json.NewDecoder(resp.Body).Decode(&report); err != nil {
|
|
return NetworkPruneResult{}, fmt.Errorf("Error retrieving network prune report: %v", err)
|
|
}
|
|
|
|
return NetworkPruneResult{Report: report}, nil
|
|
}
|