ratelimit

package
v0.0.0-...-3a8f516 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateBackoff

func CalculateBackoff(attempt int) time.Duration

CalculateBackoff calculates exponential backoff with jitter.

func ShouldRetry

func ShouldRetry(resp *http.Response) bool

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

func NewLimiter(limit int) *Limiter

NewLimiter creates a new rate limiter with default settings.

func (*Limiter) SetRetryAfter

func (l *Limiter) SetRetryAfter(duration time.Duration)

SetRetryAfter sets the retry-after duration.

func (*Limiter) Status

func (l *Limiter) Status() (remaining, limit int, resetTime time.Time)

Status returns current rate limit status.

func (*Limiter) UpdateFromHeaders

func (l *Limiter) UpdateFromHeaders(resp *http.Response)

UpdateFromHeaders updates rate limit information from response headers. Supports GitHub (X-RateLimit-*) and GitLab (RateLimit-*) headers.

func (*Limiter) Wait

func (l *Limiter) Wait(ctx context.Context) error

Wait blocks until rate limit allows making a request.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL