github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/client/build_prune.go (about) 1 package client // import "github.com/Prakhar-Agarwal-byte/moby/client" 2 3 import ( 4 "context" 5 "encoding/json" 6 "net/url" 7 "strconv" 8 9 "github.com/Prakhar-Agarwal-byte/moby/api/types" 10 "github.com/Prakhar-Agarwal-byte/moby/api/types/filters" 11 "github.com/pkg/errors" 12 ) 13 14 // BuildCachePrune requests the daemon to delete unused cache data 15 func (cli *Client) BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error) { 16 if err := cli.NewVersionError(ctx, "1.31", "build prune"); err != nil { 17 return nil, err 18 } 19 20 report := types.BuildCachePruneReport{} 21 22 query := url.Values{} 23 if opts.All { 24 query.Set("all", "1") 25 } 26 query.Set("keep-storage", strconv.Itoa(int(opts.KeepStorage))) 27 f, err := filters.ToJSON(opts.Filters) 28 if err != nil { 29 return nil, errors.Wrap(err, "prune could not marshal filters option") 30 } 31 query.Set("filters", f) 32 33 serverResp, err := cli.post(ctx, "/build/prune", query, nil, nil) 34 defer ensureReaderClosed(serverResp) 35 36 if err != nil { 37 return nil, err 38 } 39 40 if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil { 41 return nil, errors.Wrap(err, "error retrieving disk usage") 42 } 43 44 return &report, nil 45 }