Skip to content

numero33/ratelimit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

numero33/ratelimit

Limit the rate of operations per time unit, use a time.Ticker. This implementation refills the bucket based on the time elapsed between requests.

Usage

Create new bucket Refills every 18 seconds with 3 new requests and the bucket limit is 25

go get github.com/numero33/ratelimit
lr, err := ratelimit.NewLimiter(WithDuration(18*time.Second), WithAmount(3), WithLimit(25))
if err != nil {
    log.Fatal("ratelimit.NewLimiter")
}

to get a request

log.print("Wait for Slot")
lr.Take()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages