Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultRetryPolicy(resp *http.Response, err error) (bool, error)
- func NewRateLimit(interval time.Duration, actions int) *rate.Limiter
- func RetryAfter(resp *http.Response, now time.Time) time.Duration
- func SetupGlobalReporter(r Reporter)
- type Backoff
- type BasicLimit
- type EndpointLimit
- type Generate
- type Item
- type Limiter
- type Reporter
- type Requester
- func (r *Requester) DisableRateLimiter() error
- func (r *Requester) EnableRateLimiter() error
- func (r *Requester) GetNonce(isNano bool) nonce.Value
- func (r *Requester) GetNonceMilli() nonce.Value
- func (r *Requester) InitiateRateLimit(ctx context.Context, e EndpointLimit) error
- func (r *Requester) SendPayload(ctx context.Context, ep EndpointLimit, newRequest Generate) error
- func (r *Requester) SetProxy(p *url.URL) error
- type RequesterOption
- type RetryPolicy
Constants ¶
const ( DefaultMaxRequestJobs int32 = 50 DefaultMaxRetryAttempts = 3 DefaultMutexLockTimeout = 50 * time.Millisecond )
Const vars for rate limiter
Variables ¶
var ( MaxRequestJobs = DefaultMaxRequestJobs MaxRetryAttempts = DefaultMaxRetryAttempts )
Vars for rate limiter
Functions ¶
func DefaultRetryPolicy ¶
DefaultRetryPolicy determines whether the request should be retried, implemented with a default strategy.
func NewRateLimit ¶
NewRateLimit creates a new RateLimit based of time interval and how many actions allowed and breaks it down to an actions-per-second basis -- Burst rate is kept as one as this is not supported for out-bound requests.
func RetryAfter ¶
RetryAfter parses the Retry-After header in the response to determine the minimum duration needed to wait before retrying.
func SetupGlobalReporter ¶
func SetupGlobalReporter(r Reporter)
SetupGlobalReporter sets a reporter interface to be used for all exchange requests
Types ¶
type Backoff ¶
Backoff determines how long to wait between request attempts.
func DefaultBackoff ¶
func DefaultBackoff() Backoff
DefaultBackoff is a default strategy for backoff after a retryable request failure.
func LinearBackoff ¶
LinearBackoff applies a backoff increasing by a base amount with each retry capped at a maximum duration.
type BasicLimit ¶
type BasicLimit struct {
// contains filtered or unexported fields
}
BasicLimit denotes basic rate limit that implements the Limiter interface does not need to set endpoint functionality.
func (*BasicLimit) Limit ¶
func (b *BasicLimit) Limit(ctx context.Context, _ EndpointLimit) error
Limit executes a single rate limit set by NewRateLimit
type EndpointLimit ¶
type EndpointLimit int
EndpointLimit defines individual endpoint rate limits that are set when New is called.
const ( Unset EndpointLimit = iota Auth UnAuth )
Const here define individual functionality sub types for rate limiting
type Generate ¶
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 Item ¶
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 }
Item is a temp item for requests
type Limiter ¶
type Limiter interface {
Limit(context.Context, EndpointLimit) error
}
Limiter interface groups rate limit functionality defined in the REST wrapper for extended rate limiting configuration i.e. Shells of rate limits with a global rate for sub rates.
type Requester ¶
type Requester struct { HTTPClient *http.Client Name string UserAgent string Nonce nonce.Nonce // contains filtered or unexported fields }
Requester struct for the request client
func New ¶
func New(name string, httpRequester *http.Client, opts ...RequesterOption) *Requester
New returns a new Requester
func (*Requester) DisableRateLimiter ¶
DisableRateLimiter disables the rate limiting system for the exchange
func (*Requester) EnableRateLimiter ¶
EnableRateLimiter enables the rate limiting system for the exchange
func (*Requester) GetNonce ¶
GetNonce returns a nonce for requests. This locks and enforces concurrent nonce FIFO on the buffered job channel
func (*Requester) GetNonceMilli ¶
GetNonceMilli returns a nonce for requests. This locks and enforces concurrent nonce FIFO on the buffered job channel this is for millisecond
func (*Requester) InitiateRateLimit ¶
func (r *Requester) InitiateRateLimit(ctx context.Context, e EndpointLimit) error
InitiateRateLimit sleeps for designated end point rate limits
func (*Requester) SendPayload ¶
SendPayload handles sending HTTP/HTTPS requests
type RequesterOption ¶
type RequesterOption func(*Requester)
RequesterOption is a function option that can be applied to configure a Requester when creating it.
func WithBackoff ¶
func WithBackoff(b Backoff) RequesterOption
WithBackoff configures the backoff strategy for a Requester.
func WithLimiter ¶
func WithLimiter(l Limiter) RequesterOption
WithLimiter configures the rate limiter for a Requester.
func WithReporter ¶
func WithReporter(rep Reporter) RequesterOption
WithReporter configures the reporter for a Requester.
func WithRetryPolicy ¶
func WithRetryPolicy(p RetryPolicy) RequesterOption
WithRetryPolicy configures the retry policy for a Requester.