CI/build: Update Go version, linters and fix minor issues (#1473)

* CI/build: Update Go version, linters and fix minor issues

* Bump golangci-lint to v1.56.1

* BinanceUS: Make uint usage consistent

* Throw blank identifiers into the trash
This commit is contained in:
Adrian Gallagher
2024-02-14 11:02:06 +11:00
committed by GitHub
parent 9ff502bac2
commit 08da42ddb7
79 changed files with 364 additions and 374 deletions

View File

@@ -656,7 +656,7 @@ func (m *apiServerManager) WebsocketClientHandler(w http.ResponseWriter, r *http
// Allow insecure origin if the Origin request header is present and not
// equal to the Host request header. Default to false
if m.remoteConfig.WebsocketRPC.AllowInsecureOrigin {
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
upgrader.CheckOrigin = func(*http.Request) bool { return true }
}
conn, err := upgrader.Upgrade(w, r, nil)

View File

@@ -10,7 +10,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/database/drivers"
)
//nolint:gocritic // Only used as a testing helper function in this package
func CreateDatabase(t *testing.T) {
t.Helper()
// fun workarounds to globals ruining testing

View File

@@ -639,7 +639,7 @@ func GetCollatedExchangeAccountInfoByCoin(accounts []account.Holdings) map[curre
func GetExchangeHighestPriceByCurrencyPair(p currency.Pair, a asset.Item) (string, error) {
result := stats.SortExchangesByPrice(p, a, true)
if len(result) == 0 {
return "", fmt.Errorf("no stats for supplied currency pair and asset type")
return "", errors.New("no stats for supplied currency pair and asset type")
}
return result[0].Exchange, nil
@@ -650,7 +650,7 @@ func GetExchangeHighestPriceByCurrencyPair(p currency.Pair, a asset.Item) (strin
func GetExchangeLowestPriceByCurrencyPair(p currency.Pair, assetType asset.Item) (string, error) {
result := stats.SortExchangesByPrice(p, assetType, false)
if len(result) == 0 {
return "", fmt.Errorf("no stats for supplied currency pair and asset type")
return "", errors.New("no stats for supplied currency pair and asset type")
}
return result[0].Exchange, nil
@@ -962,7 +962,7 @@ func genCert(targetDir string) error {
certData := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
if certData == nil {
return fmt.Errorf("cert data is nil")
return errors.New("cert data is nil")
}
b, err := x509.MarshalECPrivateKey(privKey)
@@ -972,7 +972,7 @@ func genCert(targetDir string) error {
keyData := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: b})
if keyData == nil {
return fmt.Errorf("key pem data is nil")
return errors.New("key pem data is nil")
}
err = file.Write(filepath.Join(targetDir, "key.pem"), keyData)

View File

@@ -653,20 +653,20 @@ func TestSubmitOrderAlreadyInStore(t *testing.T) {
Exchange: testExchange,
}
submitResp, err := submitReq.DeriveSubmitResponse("batman.obvs")
assert.Nil(t, err, "Deriving a SubmitResp should not error")
assert.NoError(t, err, "Deriving a SubmitResp should not error")
id, err := uuid.NewV4()
assert.Nil(t, err, "uuid should not error")
assert.NoError(t, err, "uuid should not error")
d, err := submitResp.DeriveDetail(id)
assert.Nil(t, err, "Derive Detail should not error")
assert.NoError(t, err, "Derive Detail should not error")
d.ClientOrderID = "SecretSquirrelSauce"
err = m.orderStore.add(d)
assert.Nil(t, err, "Adding an order should not error")
assert.NoError(t, err, "Adding an order should not error")
resp, err := m.SubmitFakeOrder(submitReq, submitResp, false)
if assert.Nil(t, err, "SumbitFakeOrder should not error that the order is already in the store") {
if assert.NoError(t, err, "SumbitFakeOrder should not error that the order is already in the store") {
assert.Equal(t, d.ClientOrderID, resp.ClientOrderID, "resp should contain the ClientOrderID from the store")
}
}
@@ -1712,7 +1712,7 @@ func TestGetByDetail(t *testing.T) {
}
assert.Nil(t, m.orderStore.getByDetail(od), "Fetching a non-stored order should return nil")
assert.Nil(t, m.orderStore.add(od), "Adding the details should not error")
assert.NoError(t, m.orderStore.add(od), "Adding the details should not error")
byOrig := m.orderStore.getByDetail(od)
byID := m.orderStore.getByDetail(id)

View File

@@ -91,21 +91,21 @@ type RPCServer struct {
func (s *RPCServer) authenticateClient(ctx context.Context) (context.Context, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return ctx, fmt.Errorf("unable to extract metadata")
return ctx, errors.New("unable to extract metadata")
}
authStr, ok := md["authorization"]
if !ok {
return ctx, fmt.Errorf("authorization header missing")
return ctx, errors.New("authorization header missing")
}
if !strings.Contains(authStr[0], "Basic") {
return ctx, fmt.Errorf("basic not found in authorization header")
return ctx, errors.New("basic not found in authorization header")
}
decoded, err := crypto.Base64Decode(strings.Split(authStr[0], " ")[1])
if err != nil {
return ctx, fmt.Errorf("unable to base64 decode authorization header")
return ctx, errors.New("unable to base64 decode authorization header")
}
cred := strings.Split(string(decoded), ":")
@@ -114,7 +114,7 @@ func (s *RPCServer) authenticateClient(ctx context.Context) (context.Context, er
if username != s.Config.RemoteControl.Username ||
password != s.Config.RemoteControl.Password {
return ctx, fmt.Errorf("username/password mismatch")
return ctx, errors.New("username/password mismatch")
}
ctx, err = account.ParseCredentialsMetadata(ctx, md)
if err != nil {
@@ -878,7 +878,7 @@ func (s *RPCServer) RemovePortfolioAddress(_ context.Context, r *gctrpc.RemovePo
func (s *RPCServer) GetForexProviders(_ context.Context, _ *gctrpc.GetForexProvidersRequest) (*gctrpc.GetForexProvidersResponse, error) {
providers := s.Config.GetForexProviders()
if len(providers) == 0 {
return nil, fmt.Errorf("forex providers is empty")
return nil, errors.New("forex providers is empty")
}
forexProviders := make([]*gctrpc.ForexProvider, len(providers))
@@ -904,7 +904,7 @@ func (s *RPCServer) GetForexRates(_ context.Context, _ *gctrpc.GetForexRatesRequ
}
if len(rates) == 0 {
return nil, fmt.Errorf("forex rates is empty")
return nil, errors.New("forex rates is empty")
}
forexRates := make([]*gctrpc.ForexRatesConversion, 0, len(rates))
@@ -2604,7 +2604,7 @@ func (s *RPCServer) GCTScriptStatus(_ context.Context, _ *gctrpc.GCTScriptStatus
Status: fmt.Sprintf("%v of %v virtual machines running", gctscript.VMSCount.Len(), s.gctScriptManager.GetMaxVirtualMachines()),
}
gctscript.AllVMSync.Range(func(k, v interface{}) bool {
gctscript.AllVMSync.Range(func(_, v interface{}) bool {
vm, ok := v.(*gctscript.VM)
if !ok {
log.Errorf(log.GRPCSys, "%v", common.GetTypeAssertError("*gctscript.VM", v))
@@ -2843,7 +2843,7 @@ func (s *RPCServer) GCTScriptListAll(context.Context, *gctrpc.GCTScriptListAllRe
resp := &gctrpc.GCTScriptStatusResponse{}
err := filepath.Walk(gctscript.ScriptPath,
func(path string, info os.FileInfo, err error) error {
func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
@@ -3290,7 +3290,7 @@ func (s *RPCServer) ConvertTradesToCandles(_ context.Context, r *gctrpc.ConvertT
return nil, err
}
if len(klineItem.Candles) == 0 {
return nil, fmt.Errorf("no candles generated from trades")
return nil, errors.New("no candles generated from trades")
}
resp := &gctrpc.GetHistoricCandlesResponse{

View File

@@ -4252,7 +4252,7 @@ func TestRPCProxyAuthClient(t *testing.T) {
},
}
dummyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
dummyHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("MEOW"))
require.NoError(t, err, "Write should not error")