github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/api/backups/download.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package backups
     5  
     6  import (
     7  	"io"
     8  	"net/http"
     9  
    10  	"github.com/juju/errors"
    11  	"github.com/juju/httprequest"
    12  
    13  	"github.com/juju/juju/apiserver/params"
    14  )
    15  
    16  type downloadParams struct {
    17  	httprequest.Route `httprequest:"GET /backups"`
    18  	Body              params.BackupsDownloadArgs `httprequest:",body"`
    19  }
    20  
    21  // Download returns an io.ReadCloser for the given backup id.
    22  func (c *Client) Download(id string) (io.ReadCloser, error) {
    23  	// Send the request.
    24  	var resp *http.Response
    25  	err := c.client.Call(
    26  		&downloadParams{
    27  			Body: params.BackupsDownloadArgs{
    28  				ID: id,
    29  			},
    30  		},
    31  		&resp,
    32  	)
    33  	if err != nil {
    34  		return nil, errors.Trace(err)
    35  	}
    36  	return resp.Body, nil
    37  }