mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	Fix defer execution (#1065)
This commit is contained in:
		
							parent
							
								
									f71a326fe2
								
							
						
					
					
						commit
						2ec2fc37a5
					
				| @ -1,7 +1,9 @@ | |||||||
| package circleci | package circleci | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"bytes" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"io/ioutil" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/url" | 	"net/url" | ||||||
| 
 | 
 | ||||||
| @ -28,7 +30,7 @@ func (client *Client) BuildsFor() ([]*Build, error) { | |||||||
| 		return builds, err | 		return builds, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err = utils.ParseJSON(&builds, resp.Body) | 	err = utils.ParseJSON(&builds, bytes.NewReader(resp)) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return builds, err | 		return builds, err | ||||||
| 	} | 	} | ||||||
| @ -42,7 +44,7 @@ var ( | |||||||
| 	circleAPIURL = &url.URL{Scheme: "https", Host: "circleci.com", Path: "/api/v1/"} | 	circleAPIURL = &url.URL{Scheme: "https", Host: "circleci.com", Path: "/api/v1/"} | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func (client *Client) circleRequest(path string) (*http.Response, error) { | func (client *Client) circleRequest(path string) ([]byte, error) { | ||||||
| 	params := url.Values{} | 	params := url.Values{} | ||||||
| 	params.Add("circle-token", client.apiKey) | 	params.Add("circle-token", client.apiKey) | ||||||
| 
 | 
 | ||||||
| @ -60,11 +62,16 @@ func (client *Client) circleRequest(path string) (*http.Response, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	defer func() { _ = resp.Body.Close() }() | 	defer func() { _ = resp.Body.Close() }() | ||||||
| 
 | 
 | ||||||
| 	if resp.StatusCode < 200 || resp.StatusCode > 299 { | 	if resp.StatusCode < 200 || resp.StatusCode > 299 { | ||||||
| 		return nil, fmt.Errorf(resp.Status) | 		return nil, fmt.Errorf(resp.Status) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return resp, nil | 	body, err := ioutil.ReadAll(resp.Body) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  | 	return body, nil | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user