https://github.com/althk/ratelimiter
An easy to use ratelimiter in golang
https://github.com/althk/ratelimiter
golang ratelimiter sliding-window-algorithm token-bucket-algorithm
Last synced: 3 months ago
JSON representation
An easy to use ratelimiter in golang
- Host: GitHub
- URL: https://github.com/althk/ratelimiter
- Owner: althk
- License: mit
- Created: 2023-10-18T19:35:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-19T18:42:24.000Z (over 1 year ago)
- Last Synced: 2025-01-12T07:09:28.156Z (4 months ago)
- Topics: golang, ratelimiter, sliding-window-algorithm, token-bucket-algorithm
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Rate Limiter

Provides the following rate limiters:
- [Token Bucket](https://en.wikipedia.org/wiki/Token_bucket)
- [Sliding Window Counter](https://blog.cloudflare.com/counting-things-a-lot-of-different-things/)The package also provides the following:
### storage drivers
- Local (in-memory)
- A rate limiter configured with this store simply stores all data locally in memory.
It evicts all keys that have not been touched in the last minute.
- Redis backed
- This provides a more reliable storage for the rate limiter.
- Every key has a TTL of one minute.
- Currently does not have TLS support.### middleware
- http
- a pluggable http middleware to make it easy for using the rate limiters.
- see [example/](example) directory for usage.### configuration
The rate limiters can be configured via the `LimiterOptions` type.
See [example/main.go](example/main.go) for hints.### TODOs
- add TLS support for Redis store
- make the error message configurable (currently it returns a 429 status code with "Quota Exceeded" as the message)
- add GRPC middleware
- allow fetching limits per IP from a config source and use custom limits per client,
and fall back to the global default limit if a client does not have a custom rate limit