ratelimiter

package
v3.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GlobalRateLimiter added in v3.0.11

type GlobalRateLimiter struct {
	Limit int // Maximum number of requests allowed
	Freq  int // Frequency window in seconds
	// contains filtered or unexported fields
}

GlobalRateLimiter enforces global rate limits across all requests.

func NewGlobalRateLimiter added in v3.0.11

func NewGlobalRateLimiter(limit, freq int) *GlobalRateLimiter

NewGlobalRateLimiter creates a new instance of a global rate limiter.

func (*GlobalRateLimiter) Wait added in v3.0.11

func (rl *GlobalRateLimiter) Wait() (bool, time.Duration)

Wait checks if the rate limit is exceeded and calculates the wait time.

type RateLimitTransport added in v3.0.11

type RateLimitTransport struct {
	Base            http.RoundTripper
	Limiter         *GlobalRateLimiter
	WaitFunc        func() (bool, time.Duration) // Wait function reference
	Logger          logger.Logger
	AdditionalDelay time.Duration // Optional constant delay
}

RateLimitTransport wraps the HTTP transport to apply rate limiting.

func (*RateLimitTransport) RoundTrip added in v3.0.11

func (rlt *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface for rate limiting.

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

func NewRateLimiter

func NewRateLimiter(getLimit, postPutDeleteLimit, getFreq, postPutDeleteFreq int) *RateLimiter

func (*RateLimiter) Wait

func (rl *RateLimiter) Wait(method string) (bool, time.Duration)

Jump to

Keyboard shortcuts

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