Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/bsm/ratelimit

Simple, thread-safe Go rate-limiter
https://github.com/bsm/ratelimit

Last synced: 26 days ago
JSON representation

Simple, thread-safe Go rate-limiter

Lists

README

        

# RateLimit

[![GoDoc](https://pkg.go.dev/badge/github.com/bsm/ratelimit)](https://pkg.go.dev/github.com/bsm/ratelimit)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

Simple, thread-safe Go rate-limiter.
Inspired by Antti Huima's algorithm on http://stackoverflow.com/a/668327

### Example

```go
package main

import (
"github.com/bsm/ratelimit/v3"
"log"
)

func main() {
// Create a new rate-limiter, allowing up-to 10 calls
// per second
rl := ratelimit.New(10, time.Second)

for i:=0; i<20; i++ {
if rl.Limit() {
fmt.Println("Doh! Over limit!")
} else {
fmt.Println("OK")
}
}
}
```

### Documentation

Full documentation is available on [pkg.go.dev](https://pkg.go.dev/github.com/bsm/ratelimit).