ratelimit

package
v0.0.0-...-f1df9ad Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReqRateLimiterMiddleware

func ReqRateLimiterMiddleware(rl *RateLimiter) func(rt http.RoundTripper) req.HttpRoundTripFunc

ReqRateLimiterMiddleware implements the Middleware interface for the req library and blocks requests based on the RateLimiter configuration. The Host of the request is used as the key for the RateLimiter.

Types

type RateLimiter

type RateLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RateLimiter allows you to defaultDelay operations on a per-key basis. I.e. only one operation for a given key can be done within the defaultDelay time

func NewRateLimiter

func NewRateLimiter(defaultDelay time.Duration) *RateLimiter

NewRateLimiter returns a new *RateLimiter for the provided defaultDelay

func (*RateLimiter) Block

func (r *RateLimiter) Block(key string)

Block blocks until an operation for key is allowed to proceed

Jump to

Keyboard shortcuts

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