diff --git a/bitfinexhttp.go b/bitfinexhttp.go index db6a4fd4..c32ecd05 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -267,6 +267,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[ client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("SendAuthenticatedHTTPRequest: Unable to send request") @@ -283,8 +284,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[ if err != nil { return errors.New("Unable to JSON response.") } - - resp.Body.Close() + return nil } diff --git a/bitstamphttp.go b/bitstamphttp.go index 8fb52a9b..54c6a38d 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -287,6 +287,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, values url.Values, client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("PostRequest: Unable to send request") @@ -304,6 +305,5 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, values url.Values, return errors.New("Unable to JSON response.") } - resp.Body.Close() return nil } \ No newline at end of file diff --git a/btcchinahttp.go b/btcchinahttp.go index a1162d64..b1475bc3 100644 --- a/btcchinahttp.go +++ b/btcchinahttp.go @@ -705,6 +705,7 @@ func (b *BTCChina) SendAuthenticatedHTTPRequest(method string, params []interfac client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("PostRequest: Unable to send request") @@ -716,7 +717,6 @@ func (b *BTCChina) SendAuthenticatedHTTPRequest(method string, params []interfac log.Printf("Recv'd :%s\n", string(contents)) } - resp.Body.Close() return nil } \ No newline at end of file diff --git a/btcehttp.go b/btcehttp.go index 87399fac..d68d5a76 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -255,6 +255,7 @@ func (b *BTCE) SendAuthenticatedHTTPRequest(method string, values url.Values) (e client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("PostRequest: Unable to send request") @@ -266,7 +267,7 @@ func (b *BTCE) SendAuthenticatedHTTPRequest(method string, values url.Values) (e log.Printf("Recieved raw: %s\n", string(contents)) } - resp.Body.Close() + return nil } \ No newline at end of file diff --git a/btcmarkets.go b/btcmarkets.go index 79f9a58a..c92020eb 100644 --- a/btcmarkets.go +++ b/btcmarkets.go @@ -126,6 +126,7 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path, data string) (error client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("PostRequest: Unable to send request") @@ -137,6 +138,5 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path, data string) (error log.Printf("Recieved raw: %s\n", string(contents)) } - resp.Body.Close() return nil } \ No newline at end of file diff --git a/common.go b/common.go index 72ac1375..fcb8e5a9 100644 --- a/common.go +++ b/common.go @@ -94,6 +94,7 @@ func CalculateNetProfit(amount, priceThen, priceNow, costs float64) (float64) { func SendHTTPRequest(url string, jsonDecode bool, result interface{}) (err error) { res, err := http.Get(url) + defer res.Body.Close() if err != nil { log.Println(err) diff --git a/huobihttp.go b/huobihttp.go index ccdaa868..73cb50d7 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -216,6 +216,7 @@ func (h *HUOBI) SendAuthenticatedRequest(method string, v url.Values) (error) { client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("PostRequest: Unable to send request") @@ -226,7 +227,6 @@ func (h *HUOBI) SendAuthenticatedRequest(method string, v url.Values) (error) { if h.Verbose { log.Printf("Recieved raw: %s\n", string(contents)) } - - resp.Body.Close() + return nil } \ No newline at end of file diff --git a/itbithttp.go b/itbithttp.go index 67b8e466..4499307b 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -280,6 +280,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("SendAuthenticatedHTTPRequest: Unable to send request") @@ -291,6 +292,5 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params log.Printf("Recieved raw: %s\n", string(contents)) } - resp.Body.Close() return nil } \ No newline at end of file diff --git a/kraken.go b/kraken.go index c2953441..2fb67f03 100644 --- a/kraken.go +++ b/kraken.go @@ -517,6 +517,7 @@ func (k *Kraken) SendAuthenticatedHTTPRequest(method string, values url.Values) client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return nil, errors.New("SendAuthenticatedHTTPRequest: Unable to send request") @@ -539,6 +540,5 @@ func (k *Kraken) SendAuthenticatedHTTPRequest(method string, values url.Values) return nil, errors.New(fmt.Sprintf("Kraken error: %s", kresp.Error)) } - resp.Body.Close() return kresp.Result, nil } \ No newline at end of file diff --git a/lakebtchttp.go b/lakebtchttp.go index a8bc72a8..9130a129 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -194,6 +194,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string) (err error client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("PostRequest: Unable to send request") @@ -205,7 +206,5 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string) (err error log.Printf("Recieved raw: %s\n", string(contents)) } - resp.Body.Close() return nil - } \ No newline at end of file diff --git a/okcoinhttp.go b/okcoinhttp.go index 4fe905ba..212a712c 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -426,6 +426,7 @@ func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values) (err client := &http.Client{} resp, err := client.Do(req) + defer resp.Body.Close() if err != nil { return errors.New("PostRequest: Unable to send request") @@ -437,7 +438,5 @@ func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values) (err log.Printf("Recieved raw: %s\n", string(contents)) } - resp.Body.Close() return nil - } \ No newline at end of file