forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
request_types.go
76 lines (66 loc) · 2.08 KB
/
request_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package request
import (
"io"
"net/http"
"time"
"github.com/idoall/gocryptotrader/common/timedmutex"
"github.com/idoall/gocryptotrader/exchanges/nonce"
)
// Const vars for rate limiter
const (
DefaultMaxRequestJobs int32 = 50
DefaultMaxRetryAttempts = 3
DefaultMutexLockTimeout = 50 * time.Millisecond
drainBodyLimit = 100000
proxyTLSTimeout = 15 * time.Second
userAgent = "User-Agent"
)
// Vars for rate limiter
var (
MaxRequestJobs = DefaultMaxRequestJobs
MaxRetryAttempts = DefaultMaxRetryAttempts
globalReporter Reporter
)
// Requester struct for the request client
type Requester struct {
HTTPClient *http.Client
limiter Limiter
reporter Reporter
Name string
UserAgent string
maxRetries int
jobs int32
Nonce nonce.Nonce
disableRateLimiter int32
backoff Backoff
retryPolicy RetryPolicy
timedLock *timedmutex.TimedMutex
}
// Item is a temp item for requests
type Item struct {
Method string
Path string
Headers map[string]string
Body io.Reader
Result interface{}
AuthRequest bool
NonceEnabled bool
Verbose bool
HTTPDebugging bool
HTTPRecording bool
IsReserved bool
// HeaderResponse for inspection of header contents package side useful for
// pagination
HeaderResponse *http.Header
}
// Backoff determines how long to wait between request attempts.
type Backoff func(n int) time.Duration
// RetryPolicy determines whether the request should be retried.
type RetryPolicy func(resp *http.Response, err error) (bool, error)
// RequesterOption is a function option that can be applied to configure a Requester when creating it.
type RequesterOption func(*Requester)
// Generate defines a closure for functionality outside of the requester to
// to generate new *http.Request on every attempt. This minimizes the chance of
// being outside of receive window if application rate limiting reduces outbound
// requests.
type Generate func() (*Item, error)