From 1f7575937119960ed4b53b4c066efe146031a35f Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 19 Oct 2014 13:35:42 +0200 Subject: [PATCH] s3: style fixes Change-Id: I0c8dacb00f57d374c3148fe5c8017a9f146d36f4 --- pkg/misc/amazon/s3/client.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pkg/misc/amazon/s3/client.go b/pkg/misc/amazon/s3/client.go index 37926013a..943ed024b 100644 --- a/pkg/misc/amazon/s3/client.go +++ b/pkg/misc/amazon/s3/client.go @@ -282,25 +282,20 @@ func (c *Client) ListBucket(bucket string, startAt string, maxKeys int) (items [ func (c *Client) Get(bucket, key string) (body io.ReadCloser, size int64, err error) { req := newReq(c.keyURL(bucket, key)) c.Auth.SignRequest(req) - var res *http.Response - res, err = c.transport().RoundTrip(req) + res, err := c.transport().RoundTrip(req) if err != nil { return } - if res.StatusCode != http.StatusOK && res != nil && res.Body != nil { - defer func() { - io.Copy(os.Stderr, res.Body) - }() + switch res.StatusCode { + case http.StatusOK: + return res.Body, res.ContentLength, nil + case http.StatusNotFound: + res.Body.Close() + return nil, 0, os.ErrNotExist + default: + res.Body.Close() + return nil, 0, fmt.Errorf("Amazon HTTP error on GET: %d", res.StatusCode) } - if res.StatusCode == http.StatusNotFound { - err = os.ErrNotExist - return - } - if res.StatusCode != http.StatusOK { - err = fmt.Errorf("Amazon HTTP error on GET: %d", res.StatusCode) - return - } - return res.Body, res.ContentLength, nil } func (c *Client) Delete(bucket, key string) error {