https://github.com/bsm/ratelimit
Simple, thread-safe Go rate-limiter
https://github.com/bsm/ratelimit
Last synced: 29 days ago
JSON representation
Simple, thread-safe Go rate-limiter
- Host: GitHub
- URL: https://github.com/bsm/ratelimit
- Owner: bsm
- License: mit
- Created: 2015-03-21T13:40:35.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2023-10-16T08:25:26.000Z (over 1 year ago)
- Last Synced: 2025-03-29T19:07:51.591Z (about 1 month ago)
- Language: Go
- Size: 18.6 KB
- Stars: 81
- Watchers: 9
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - RateLimit
README
# RateLimit
[](https://pkg.go.dev/github.com/bsm/ratelimit)
[](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 mainimport (
"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).