mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 23:16:51 +00:00
modernise: Run new gopls modernise tool against the codebase and fix minor issues (#1826)
* modernise: Run new gopls modernise tool against codebase
* Address shazbert's nits
* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling
* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS
* refactor: Various slice usage improvements and rename TODO
* tranches: Revert deleteByID changes due to performance decrease
Shazbert was a F1 driver in a past lifetime 🏎️
* tranches: Simply retrieve copy
Thanks to shazbert
* documentation: Sort contributors list by contributions
* tranches: Remove deadcode in deleteByID
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -32,11 +33,11 @@ func (c *clientTracker) checkAndRegister(newClient *http.Client) error {
|
||||
}
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
for x := range c.clients {
|
||||
if newClient == c.clients[x] {
|
||||
return errCannotReuseHTTPClient
|
||||
}
|
||||
|
||||
if slices.Contains(c.clients, newClient) {
|
||||
return errCannotReuseHTTPClient
|
||||
}
|
||||
|
||||
c.clients = append(c.clients, newClient)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -14,12 +15,7 @@ import (
|
||||
func (c *clientTracker) contains(check *http.Client) bool {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
for x := range c.clients {
|
||||
if check == c.clients[x] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(c.clients, check)
|
||||
}
|
||||
|
||||
func TestCheckAndRegister(t *testing.T) {
|
||||
|
||||
@@ -37,7 +37,7 @@ type EndpointLimit uint16
|
||||
type Weight uint8
|
||||
|
||||
// RateLimitDefinitions is a map of endpoint limits to rate limiters
|
||||
type RateLimitDefinitions map[interface{}]*RateLimiterWithWeight
|
||||
type RateLimitDefinitions map[any]*RateLimiterWithWeight
|
||||
|
||||
// RateLimiterWithWeight is a rate limiter coupled with a weight count which
|
||||
// refers to the number or weighting of the request. This is used to define
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
@@ -217,10 +218,7 @@ func (r *Requester) doRequest(ctx context.Context, endpoint EndpointLimit, newRe
|
||||
|
||||
after := RetryAfter(resp, time.Now())
|
||||
backoff := r.backoff(attempt)
|
||||
delay := backoff
|
||||
if after > backoff {
|
||||
delay = after
|
||||
}
|
||||
delay := max(backoff, after)
|
||||
|
||||
if dl, ok := req.Context().Deadline(); ok && dl.Before(time.Now().Add(delay)) {
|
||||
if err != nil {
|
||||
@@ -265,9 +263,7 @@ func (r *Requester) doRequest(ctx context.Context, endpoint EndpointLimit, newRe
|
||||
}
|
||||
|
||||
if p.HeaderResponse != nil {
|
||||
for k, v := range resp.Header {
|
||||
(*p.HeaderResponse)[k] = v
|
||||
}
|
||||
maps.Copy(*p.HeaderResponse, resp.Header)
|
||||
}
|
||||
|
||||
if resp.StatusCode < http.StatusOK ||
|
||||
|
||||
@@ -565,7 +565,7 @@ func TestEnableDisableRateLimit(t *testing.T) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
var resp interface{}
|
||||
var resp any
|
||||
err = r.SendPayload(ctx, Auth, func() (*Item, error) {
|
||||
return &Item{
|
||||
Method: http.MethodGet,
|
||||
|
||||
@@ -45,7 +45,7 @@ type Item struct {
|
||||
Path string
|
||||
Headers map[string]string
|
||||
Body io.Reader
|
||||
Result interface{}
|
||||
Result any
|
||||
NonceEnabled bool
|
||||
Verbose bool
|
||||
HTTPDebugging bool
|
||||
|
||||
Reference in New Issue
Block a user