diff --git a/api.go b/api.go index fde3605..b7d3382 100644 --- a/api.go +++ b/api.go @@ -50,7 +50,7 @@ func (api *TastytradeAPI) fetchData(url string) (map[string]interface{}, error) if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode >= 400 && resp.StatusCode < 500 { return nil, fmt.Errorf("client error occurred: status code %d", resp.StatusCode) @@ -78,7 +78,7 @@ func (api *TastytradeAPI) fetchDataAndUnmarshal(urlVal string, v interface{}) er if err != nil { return err } - defer resp.Body.Close() + defer func() { _= resp.Body.Close() }() if resp.StatusCode >= 400 && resp.StatusCode < 500 { return fmt.Errorf("client error occurred: status code %d", resp.StatusCode) diff --git a/api_test.go b/api_test.go index 75b7f95..35cbb5b 100644 --- a/api_test.go +++ b/api_test.go @@ -8,7 +8,7 @@ import ( func TestFetchData(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"data": "test"}`)) + _,_ = rw.Write([]byte(`{"data": "test"}`)) })) defer server.Close() @@ -26,7 +26,7 @@ func TestFetchData(t *testing.T) { func TestFetchDataAndUnmarshal(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"data": "test"}`)) + _,_ = rw.Write([]byte(`{"data": "test"}`)) })) defer server.Close() diff --git a/balances_test.go b/balances_test.go index 063777e..ea02b8f 100644 --- a/balances_test.go +++ b/balances_test.go @@ -14,7 +14,7 @@ func TestGetAccountBalances(t *testing.T) { t.Errorf("got: %s, want: /accounts/123/balances", req.URL.String()) } // Send response to be tested - rw.Write([]byte(`{"data": {"account-number": "123", "cash-balance": "1000"}, "context": "test"}`)) + _,_ = rw.Write([]byte(`{"data": {"account-number": "123", "cash-balance": "1000"}, "context": "test"}`)) })) // Close the server when test finishes defer server.Close() diff --git a/crypto_test.go b/crypto_test.go index c7f6697..5deec74 100644 --- a/crypto_test.go +++ b/crypto_test.go @@ -9,7 +9,7 @@ import ( func TestListCryptocurrencies(t *testing.T) { // Create a test server that returns a dummy response ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(`{"data": {"items": []}, "context": "/instruments/cryptocurrencies"}`)) + _,_ = w.Write([]byte(`{"data": {"items": []}, "context": "/instruments/cryptocurrencies"}`)) })) defer ts.Close() @@ -33,7 +33,7 @@ func TestListCryptocurrencies(t *testing.T) { func TestGetCryptocurrency(t *testing.T) { // Create a test server that returns a dummy response ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(`{"data": {"symbol": "BTC/USD"}, "context": "/instruments/cryptocurrencies/BTC%2FUSD"}`)) + _,_ = w.Write([]byte(`{"data": {"symbol": "BTC/USD"}, "context": "/instruments/cryptocurrencies/BTC%2FUSD"}`)) })) defer ts.Close() diff --git a/customer_test.go b/customer_test.go index acf026e..5cf56c0 100644 --- a/customer_test.go +++ b/customer_test.go @@ -8,7 +8,7 @@ import ( func TestGetCustomerInfo(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"id": "123", "first-name": "John", "last-name": "Doe"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"id": "123", "first-name": "John", "last-name": "Doe"}}`)) })) defer server.Close() @@ -30,7 +30,7 @@ func TestGetCustomerInfo(t *testing.T) { func TestListCustomerAccounts(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"account": {"account-number": "123"}}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"account": {"account-number": "123"}}]}}`)) })) defer server.Close() @@ -56,7 +56,7 @@ func TestListCustomerAccounts(t *testing.T) { func TestGetAccount(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"account-number": "123"}}`)) + _,_= rw.Write([]byte(`{"context": "test", "data": {"account-number": "123"}}`)) })) defer server.Close() diff --git a/equity_test.go b/equity_test.go index acdfe5e..2d2a6c8 100644 --- a/equity_test.go +++ b/equity_test.go @@ -8,7 +8,7 @@ import ( func TestGetEquityData(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"symbol": "AAPL"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"symbol": "AAPL"}}`)) })) defer server.Close() @@ -30,7 +30,7 @@ func TestGetEquityData(t *testing.T) { func TestListEquities(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL"}, {"symbol": "GOOG"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL"}, {"symbol": "GOOG"}]}}`)) })) defer server.Close() @@ -52,7 +52,7 @@ func TestListEquities(t *testing.T) { func TestListActiveEquities(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL"}, {"symbol": "GOOG"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL"}, {"symbol": "GOOG"}]}}`)) })) defer server.Close() diff --git a/futures_test.go b/futures_test.go index eda8cf3..e9487a7 100644 --- a/futures_test.go +++ b/futures_test.go @@ -12,7 +12,7 @@ func TestQueryFutures(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"data": {"items": [{"symbol": "AAPL"}]}}`)) + _,_ = rw.Write([]byte(`{"data": {"items": [{"symbol": "AAPL"}]}}`)) })) defer server.Close() @@ -52,7 +52,7 @@ func TestQueryFuturesWithParams(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"data": {"items": [{"symbol": "AAPL", "product-code": "123"}]}}`)) + _,_ = rw.Write([]byte(`{"data": {"items": [{"symbol": "AAPL", "product-code": "123"}]}}`)) })) defer server.Close() @@ -85,7 +85,7 @@ func TestGetFuture(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"data": {"symbol": "AAPL"}}`)) + _,_ = rw.Write([]byte(`{"data": {"symbol": "AAPL"}}`)) })) defer server.Close() @@ -107,7 +107,7 @@ func TestGetFutureOptionProduct(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"context": "test", "data": {"root-symbol": "AAPL"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"root-symbol": "AAPL"}}`)) })) defer server.Close() @@ -133,7 +133,7 @@ func TestListFutureOptions(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "instrument-type": "future-option"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "instrument-type": "future-option"}]}}`)) })) defer server.Close() @@ -163,7 +163,7 @@ func TestListFutureOptionChainsNested(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"context": "test", "data": {"futures": [{"symbol": "AAPL"}], "option-chains": [{"underlying-symbol": "AAPL"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"futures": [{"symbol": "AAPL"}], "option-chains": [{"underlying-symbol": "AAPL"}]}}`)) })) defer server.Close() @@ -201,7 +201,7 @@ func TestListFutureOptionChainsDetailed(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "underlying-symbol": "AAPL"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "underlying-symbol": "AAPL"}]}}`)) })) defer server.Close() @@ -235,7 +235,7 @@ func TestGetFutureOption(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"context": "test", "data": {"symbol": "AAPL", "instrument-type": "future-option"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"symbol": "AAPL", "instrument-type": "future-option"}}`)) })) defer server.Close() @@ -261,7 +261,7 @@ func TestListFutureOptionProducts(t *testing.T) { if req.URL.String() != expectedURL { t.Errorf("expected URL to be %s, got %s", expectedURL, req.URL.String()) } - rw.Write([]byte(`{"context": "test", "data": {"items": [{"root-symbol": "AAPL", "instrument-type": "future-option"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"root-symbol": "AAPL", "instrument-type": "future-option"}]}}`)) })) defer server.Close() diff --git a/option_test.go b/option_test.go index d57c650..ad36906 100644 --- a/option_test.go +++ b/option_test.go @@ -8,7 +8,7 @@ import ( func TestListOptionsChainsDetailed(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "underlying-symbol": "AAPL"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "underlying-symbol": "AAPL"}]}}`)) })) defer server.Close() @@ -38,7 +38,7 @@ func TestListOptionsChainsDetailed(t *testing.T) { func TestListOptionChainsNested(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"underlying-symbol": "AAPL", "root-symbol": "AAPL"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"underlying-symbol": "AAPL", "root-symbol": "AAPL"}]}}`)) })) defer server.Close() @@ -64,7 +64,7 @@ func TestListOptionChainsNested(t *testing.T) { func TestGetOptionChainsCompact(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"underlying-symbol": "AAPL", "root-symbol": "AAPL"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"underlying-symbol": "AAPL", "root-symbol": "AAPL"}]}}`)) })) defer server.Close() @@ -90,7 +90,7 @@ func TestGetOptionChainsCompact(t *testing.T) { func TestGetEquityOptions(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "instrument-type": "equity-option"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "instrument-type": "equity-option"}]}}`)) })) defer server.Close() @@ -116,7 +116,7 @@ func TestGetEquityOptions(t *testing.T) { func TestGetEquityOption(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"symbol": "AAPL", "instrument-type": "equity-option"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"symbol": "AAPL", "instrument-type": "equity-option"}}`)) })) defer server.Close() diff --git a/positions_test.go b/positions_test.go index 525e751..1025fae 100644 --- a/positions_test.go +++ b/positions_test.go @@ -8,7 +8,7 @@ import ( func TestGetPositions(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "quantity": "100"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "quantity": "100"}]}}`)) })) defer server.Close() diff --git a/sessions.go b/sessions.go index b562693..48fdf12 100644 --- a/sessions.go +++ b/sessions.go @@ -50,7 +50,7 @@ func (api *TastytradeAPI) Authenticate2(username, password string, remember bool if err != nil { return err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return fmt.Errorf("authentication failed: status code %d", resp.StatusCode) @@ -97,7 +97,7 @@ func (api *TastytradeAPI) AuthRemember(remember bool) error { if err != nil { return err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return fmt.Errorf("authentication failed: status code %d", resp.StatusCode) diff --git a/sessions_test.go b/sessions_test.go index c59ee8d..a998875 100644 --- a/sessions_test.go +++ b/sessions_test.go @@ -9,7 +9,7 @@ import ( func TestAuthenticate(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"user": {"email": "test@example.com", "username": "testuser", "external-id": "123", "is-confirmed": true}, "session-token": "testtoken"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"user": {"email": "test@example.com", "username": "testuser", "external-id": "123", "is-confirmed": true}, "session-token": "testtoken"}}`)) })) defer server.Close() @@ -31,7 +31,7 @@ func TestAuthenticate(t *testing.T) { func TestAuthenticate2(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"user": {"email": "test@example.com", "username": "testuser", "external-id": "123", "is-confirmed": true}, "session-token": "testtoken", "remember-token": "remember", "session-expiration": "2024-09-12T20:25:32.440Z"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"user": {"email": "test@example.com", "username": "testuser", "external-id": "123", "is-confirmed": true}, "session-token": "testtoken", "remember-token": "remember", "session-expiration": "2024-09-12T20:25:32.440Z"}}`)) })) defer server.Close() @@ -58,7 +58,7 @@ func TestAuthenticate2(t *testing.T) { func TestAuthRemember(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"user": {"email": "test@example.com", "username": "testuser", "external-id": "123", "is-confirmed": true}, "session-token": "testtoken", "remember-token": "remember-new"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"user": {"email": "test@example.com", "username": "testuser", "external-id": "123", "is-confirmed": true}, "session-token": "testtoken", "remember-token": "remember-new"}}`)) })) var err error defer server.Close() diff --git a/status_test.go b/status_test.go index 1b9febc..7a1a5a1 100644 --- a/status_test.go +++ b/status_test.go @@ -8,7 +8,7 @@ import ( func TestGetAccountTradingStatus(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"account-number": "123456", "day-trade-count": 1}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"account-number": "123456", "day-trade-count": 1}}`)) })) defer server.Close() diff --git a/transactions_test.go b/transactions_test.go index b251dcf..b148ff1 100644 --- a/transactions_test.go +++ b/transactions_test.go @@ -8,7 +8,7 @@ import ( func TestGetTransactions(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"items": [{"id": 1, "account-number": "123456", "symbol": "AAPL", "transaction-type": "buy"}]}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"items": [{"id": 1, "account-number": "123456", "symbol": "AAPL", "transaction-type": "buy"}]}}`)) })) defer server.Close() @@ -46,7 +46,7 @@ func TestGetTransactions(t *testing.T) { func TestGetTransaction(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"context": "test", "data": {"id": 1, "account-number": "123", "symbol": "AAPL", "instrument-type": "equity-option"}}`)) + _,_ = rw.Write([]byte(`{"context": "test", "data": {"id": 1, "account-number": "123", "symbol": "AAPL", "instrument-type": "equity-option"}}`)) })) defer server.Close() @@ -68,7 +68,7 @@ func TestGetTransaction(t *testing.T) { func TestGetTransactionsPagination(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Write([]byte(`{"api-version": "1.0", "context": "test", "data": {"items": [{"id": 1, "account-number": "123", "symbol": "AAPL", "instrument-type": "equity-option"}]}, "pagination": {"per-page": 1, "total-items": 10}}`)) + _,_ = rw.Write([]byte(`{"api-version": "1.0", "context": "test", "data": {"items": [{"id": 1, "account-number": "123", "symbol": "AAPL", "instrument-type": "equity-option"}]}, "pagination": {"per-page": 1, "total-items": 10}}`)) })) defer server.Close() diff --git a/warrants_test.go b/warrants_test.go index 5d0aea1..ea3611a 100644 --- a/warrants_test.go +++ b/warrants_test.go @@ -9,7 +9,7 @@ import ( func TestListWarrants(t *testing.T) { // Create a test server that returns a dummy response ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(`{"data": {"items": []}, "context": "/instruments/warrants"}`)) + _,_ = w.Write([]byte(`{"data": {"items": []}, "context": "/instruments/warrants"}`)) })) defer ts.Close() @@ -33,7 +33,7 @@ func TestListWarrants(t *testing.T) { func TestGetWarrant(t *testing.T) { // Create a test server that returns a dummy response ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(`{"data": {"symbol": "SEPAW"}, "context": "/instruments/warrants/SEPAW"}`)) + _,_ = w.Write([]byte(`{"data": {"symbol": "SEPAW"}, "context": "/instruments/warrants/SEPAW"}`)) })) defer ts.Close()