github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/build_prune.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"golang.org/x/net/context"
     9  )
    10  
    11  // BuildCachePrune requests the daemon to delete unused cache data
    12  func (cli *Client) BuildCachePrune(ctx context.Context) (*types.BuildCachePruneReport, error) {
    13  	if err := cli.NewVersionError("1.31", "build prune"); err != nil {
    14  		return nil, err
    15  	}
    16  
    17  	report := types.BuildCachePruneReport{}
    18  
    19  	serverResp, err := cli.post(ctx, "/build/prune", nil, nil, nil)
    20  	if err != nil {
    21  		return nil, err
    22  	}
    23  	defer ensureReaderClosed(serverResp)
    24  
    25  	if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil {
    26  		return nil, fmt.Errorf("Error retrieving disk usage: %v", err)
    27  	}
    28  
    29  	return &report, nil
    30  }