limit

package
v0.0.0-...-26e49b3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: AGPL-3.0 Imports: 3 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLimiter = &RateLimiter{
	Map:   make(map[string]chan struct{}),
	Mutex: &sync.RWMutex{},
}

DefaultLimiter is the RateLimiter used by the package-level Request and NonBlockingRequest.

Functions

func NonBlockingRequest

func NonBlockingRequest(u string, perMinute int) bool

NonBlockingRequest is a NonBlockingRequest with DefaultLimiter.

func Request

func Request(u string, perMinute int)

Request is a Request with DefaultLimiter.

Types

type RateLimiter

type RateLimiter struct {
	Map   map[string]chan struct{}
	Mutex *sync.RWMutex
}

RateLimiter is a simple rate limiter.

func (*RateLimiter) NonBlockingRequest

func (s *RateLimiter) NonBlockingRequest(u string, perMinute int) bool

NonBlockingRequest checks if it can do a request. If it can't, it returns false, else it returns true if the request succeded.

func (*RateLimiter) Request

func (s *RateLimiter) Request(u string, perMinute int)

Request is a simple request. Blocks until it can make the request.

Jump to

Keyboard shortcuts

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