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
1022 B
Go
40 lines
1022 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/moby/moby/api/types/container"
|
|
)
|
|
|
|
// ContainerPruneOptions holds parameters to prune containers.
|
|
type ContainerPruneOptions struct {
|
|
Filters Filters
|
|
}
|
|
|
|
// ContainerPruneResult holds the result from the [Client.ContainerPrune] method.
|
|
type ContainerPruneResult struct {
|
|
Report container.PruneReport
|
|
}
|
|
|
|
// ContainerPrune requests the daemon to delete unused data
|
|
func (cli *Client) ContainerPrune(ctx context.Context, opts ContainerPruneOptions) (ContainerPruneResult, error) {
|
|
query := url.Values{}
|
|
opts.Filters.updateURLValues(query)
|
|
|
|
resp, err := cli.post(ctx, "/containers/prune", query, nil, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return ContainerPruneResult{}, err
|
|
}
|
|
|
|
var report container.PruneReport
|
|
if err := json.NewDecoder(resp.Body).Decode(&report); err != nil {
|
|
return ContainerPruneResult{}, fmt.Errorf("Error retrieving disk usage: %v", err)
|
|
}
|
|
|
|
return ContainerPruneResult{Report: report}, nil
|
|
}
|