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: 3 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 (over 9 years ago)
- Default Branch: main
- Last Pushed: 2023-10-16T08:25:26.000Z (about 1 year ago)
- Last Synced: 2024-10-23T02:00:09.464Z (17 days ago)
- Language: Go
- Size: 18.6 KB
- Stars: 80
- Watchers: 10
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - RateLimit
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 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).