ratelimit

package
v0.0.0-...-601228c Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

pkg/common/ratelimit/ratelimit.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter struct {
	Available      int           // Available requests remaining
	Limit          int           // Total requests allowed in the interval
	Interval       time.Duration // Interval to reset the rate limiter
	Requests       int           // Total requests made
	ResetHeaders   bool          // Flag to check if the rate limiter retrieves info from specific headers
	ResetTimestamp int64         // Timestamp to reset the rate limiter
	RetryAfter     int           // Retry after time
	TimeUntilReset time.Duration // Time until the rate limiter resets
	UsesRetryAfter bool          // Flag to check if the rate limiter uses a retry after value
	Log            *log.Logger   // Logger for the rate limiter
	// contains filtered or unexported fields
}

RateLimiter struct defines the fields for the rate limiter

func NewRateLimiter

func NewRateLimiter(args ...interface{}) *RateLimiter

NewRateLimiter creates a new RateLimiter instance with the given parameters

func (*RateLimiter) Start

func (rl *RateLimiter) Start()

Start begins the rate limiter's internal timer

func (*RateLimiter) Stop

func (rl *RateLimiter) Stop()

Stop terminates the rate limiter's internal timer

func (*RateLimiter) UpdateFromHeaders

func (rl *RateLimiter) UpdateFromHeaders(headers http.Header)

func (*RateLimiter) Wait

func (rl *RateLimiter) Wait()

Throttle requests based on the remaining available rate limit.

Jump to

Keyboard shortcuts

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