fix defer on nil object

This commit is contained in:
jgsqware 2016-09-29 07:32:35 +02:00
parent 8bd785d8c1
commit fa27815901
5 changed files with 5 additions and 7 deletions

View File

@ -47,11 +47,10 @@ func analyzeLayer(id string) (v1.LayerEnvelope, error) {
lURI := fmt.Sprintf("%v/layers/%v?vulnerabilities", uri, id)
response, err := http.Get(lURI)
defer response.Body.Close()
if err != nil {
return v1.LayerEnvelope{}, fmt.Errorf("analysing layer %v: %v", id, err)
}
defer response.Body.Close()
var analysis v1.LayerEnvelope
err = json.NewDecoder(response.Body).Decode(&analysis)

View File

@ -10,12 +10,11 @@ import (
func IsHealthy() bool {
logrus.Debugln("requesting health on: " + healthURI)
response, err := http.Get(healthURI)
defer response.Body.Close()
if err != nil {
logrus.Errorf("requesting Clair health: %v", err)
return false
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return false

View File

@ -89,11 +89,11 @@ func pushLayer(layer v1.LayerEnvelope) error {
request.Header.Set("Content-Type", "application/json")
response, err := (&http.Client{}).Do(request)
defer response.Body.Close()
if err != nil {
return fmt.Errorf("pushing layer to clair: %v", err)
}
defer response.Body.Close()
if response.StatusCode != 201 {
if response.StatusCode == 422 {

View File

@ -9,10 +9,10 @@ import (
func Versions() (interface{}, error) {
Config()
response, err := http.Get(uri + "/versions")
defer response.Body.Close()
if err != nil {
return nil, fmt.Errorf("requesting Clair version: %v", err)
}
defer response.Body.Close()
var versionBody interface{}
err = json.NewDecoder(response.Body).Decode(&versionBody)

View File

@ -52,11 +52,11 @@ func AuthenticateResponse(client *http.Client, dockerResponse *http.Response, re
req.SetBasicAuth(authConfig.Username, authConfig.Password)
response, err := client.Do(req)
defer response.Body.Close()
if err != nil {
return err
}
defer response.Body.Close()
if response.StatusCode == http.StatusUnauthorized {
return ErrUnauthorized