Documentation
¶
Overview ¶
Package ratelimit provides rate limiting functionality for API calls.
This package implements a token bucket algorithm to prevent exceeding API rate limits when interacting with Git forges (GitHub, GitLab, Gitea).
Usage ¶
limiter := ratelimit.NewLimiter(5000) // 5000 requests/hour limiter.Wait() // Block until request allowed remaining, limit, reset := limiter.Status()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateBackoff ¶
CalculateBackoff calculates exponential backoff with jitter.
func ShouldRetry ¶
ShouldRetry determines if a response indicates we should retry.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter handles API rate limiting with retry logic.
func NewLimiter ¶
NewLimiter creates a new rate limiter with default settings.
func (*Limiter) SetRetryAfter ¶
SetRetryAfter sets the retry-after duration.
func (*Limiter) UpdateFromHeaders ¶
UpdateFromHeaders updates rate limit information from response headers. Supports GitHub (X-RateLimit-*) and GitLab (RateLimit-*) headers.
type RetryableError ¶
type RetryableError struct {
Err error
RetryAfter time.Duration
AttemptsLeft int
NextRetryTime time.Time
}
RetryableError represents an error that can be retried.
func (*RetryableError) Error ¶
func (e *RetryableError) Error() string
func (*RetryableError) IsRetryable ¶
func (e *RetryableError) IsRetryable() bool
IsRetryable returns true if the error is retryable.
func (*RetryableError) Unwrap ¶
func (e *RetryableError) Unwrap() error
Unwrap returns the underlying error.