Skip to content

Commit

Permalink
Merge pull request deis#4068 from Joshua-Anderson/fix-defers
Browse files Browse the repository at this point in the history
fix(client-go): defer deferred closing of body until after error check.
  • Loading branch information
carmstrong committed Jul 20, 2015
2 parents 2c6dfe4 + 82fafec commit 1755334
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client-go/controller/client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func Register(controllerURL url.URL, username string, password string, email str
addUserAgent(&headers)

res, err := rawRequest(client, "POST", controllerURL.String(), bytes.NewBuffer(body), headers, 201)
defer res.Body.Close()

if err != nil {
return err
}
defer res.Body.Close()

fmt.Printf("Registered %s\n", username)

Expand Down Expand Up @@ -72,11 +72,11 @@ func Login(controllerURL url.URL, username string, password string, sslVerify bo
addUserAgent(&headers)

res, err := rawRequest(client, "POST", controllerURL.String(), bytes.NewBuffer(body), headers, 200)
defer res.Body.Close()

if err != nil {
return err
}
defer res.Body.Close()

resBody, err := ioutil.ReadAll(res.Body)

Expand Down
4 changes: 2 additions & 2 deletions client-go/controller/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func (c Client) BasicRequest(method string, path string, body []byte) (string, i
if err != nil {
return "", -1, err
}
defer res.Body.Close()

resBody, err := ioutil.ReadAll(res.Body)
defer res.Body.Close()

if err != nil {
return "", -1, err
Expand All @@ -114,12 +114,12 @@ Make sure that the Controller URI is correct and the server is running.`
}

res, err := client.Do(req)
defer res.Body.Close()

if err != nil {
fmt.Printf(errorMessage+"\n", baseURL)
return err
}
defer res.Body.Close()

if res.StatusCode != 401 {
return fmt.Errorf(errorMessage, baseURL)
Expand Down

0 comments on commit 1755334

Please sign in to comment.