Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMaximumRetryAttempts = errors.New("maximum retry attempts reached")
Functions ¶
This section is empty.
Types ¶
type RateLimitAlign ¶
RateLimitAlign is a function that's used after a response is retrieved to align the rate limit. It takes the request context and the HTTP response as parameters and returns the actual rate limit values. If the alignment is successful, it returns the rate limit, remaining limit, and a boolean flag indicating success. If the alignment is not possible or the response does not contain the rate limit information, the function should return zero values for the rate limit and remaining limit, and false for the success flag. This function can be used to handle cases where the API returns a status code other than 429 (Too Many Requests) but the rate limit has been reached such as GraphQL.
type RateLimitTransport ¶
type RateLimitTransport struct { Transport http.RoundTripper // The underlying HTTP transport Align RateLimitAlign // The rate limit align function Limiter *limiter.Limiter // The rate limiter LimiterKey string // The key used to identify the rate limiter }
RateLimitTransport is a custom transport that handles rate limiting of HTTP requests. It wraps an existing http.RoundTripper implementation and enforces rate limits using a limiter.
func (RateLimitTransport) L ¶
func (rt RateLimitTransport) L(ctx context.Context) *zap.Logger
L returns a logger instance associated with the RateLimitTransport. It provides a structured logging experience with trace information.
func (*RateLimitTransport) RoundTrip ¶
RoundTrip implements the http.RoundTripper interface. It performs the HTTP request and enforces rate limits using the configured limiter. If the rate limit is reached, it waits for the duration until the rate limit resets before retrying the request. If the response status code is 429 (Too Many Requests), it increments the rate limit count by the limit value. If an alignment function is provided, it adjusts the rate limit based on the actual values returned by the alignment function.
type RetryFunc ¶ added in v0.0.7
RetryFunc returning the response and possible error, if true is returned it'll retry given the maximum attempts aren't exceeded.
type RetryTransport ¶
type RetryTransport struct { Transport http.RoundTripper // The underlying HTTP transport RetryFunc RetryFunc // The retry function filter, if true is returned it'll retry RetryCount int // The maximum number of retry attempts RetryDuration time.Duration // The duration to wait between retries }
RetryTransport is a custom transport that implements retry logic for HTTP requests. It wraps an existing http.RoundTripper implementation and retries failed requests up to a maximum count.
func (RetryTransport) L ¶
func (rt RetryTransport) L(ctx context.Context) *zap.Logger
L returns a logger instance associated with the RetryTransport. It provides a structured logging experience with trace information.
func (*RetryTransport) RoundTrip ¶
RoundTrip implements the http.RoundTripper interface. It performs the HTTP request and retries failed requests up to the maximum retry count. If a timeout error occurs, it logs the error and waits for the specified retry duration before retrying. If a non-timeout error occurs, it immediately returns the error without retrying.
type UserAgentGenerator ¶
type UserAgentGenerator func() string
UserAgentGenerator is a function type that returns a string representing a User-Agent value. Implementations of this function can be used to generate custom User-Agent strings. For example, you can use `github.com/corpix/uarand`.GetRandom().
type UserAgentTransport ¶
type UserAgentTransport struct { Generator UserAgentGenerator // The User-Agent generator function Transport http.RoundTripper // The underlying HTTP transport }
UserAgentTransport is a custom transport that sets a User-Agent header on outgoing HTTP requests. It wraps an existing http.RoundTripper implementation and adds the functionality to set a custom User-Agent.
func (*UserAgentTransport) RoundTrip ¶
RoundTrip implements the http.RoundTripper interface. It sets the User-Agent header on the request using the provided Generator (if not nil), and delegates the actual request handling to the wrapped Transport. The response and error from the wrapped Transport.RoundTrip method are returned.