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