Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0verread/goralim
A rate limiting package for Go to handle distributed workloads
https://github.com/0verread/goralim
distributed-systems golang rate-limiter rate-limiting redis
Last synced: about 2 months ago
JSON representation
A rate limiting package for Go to handle distributed workloads
- Host: GitHub
- URL: https://github.com/0verread/goralim
- Owner: 0verread
- License: mit
- Created: 2024-03-13T00:41:52.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-04-27T16:28:40.000Z (5 months ago)
- Last Synced: 2024-06-21T14:11:36.513Z (3 months ago)
- Topics: distributed-systems, golang, rate-limiter, rate-limiting, redis
- Language: Go
- Homepage:
- Size: 52.7 KB
- Stars: 140
- Watchers: 3
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![banner](images/banner.png)
# Goralim
[goralim](https://github.com/0verread/goralim) is a Golang package that provides a rate limiter based on [Token bucket](https://en.wikipedia.org/wiki/Token_bucket) algorithm. It is capable to handle distributed workload with its redis database support. It has HTTP server middleware support (as of now).
> 🚧 this is a beta version now and under active development. For production use, fork it and make changes based on your need.
## Install
```bash
go get "github.com/0verread/goralim" -m
```
## Usage```golang
package mainimport (
"fmt"
"net/http"goralim "github.com/0verread/goralim"
)func main() {
// Redis initialization
config := goralim.RedisConfig{
HOST: "127.0.0.1",
PORT: 6379,
// password
PASS: "",
}
redisStore := goralim.NewRedisClient(config)// setup rate limiter for a key (key can be userId/client)
// 10 is bucket size, 5 is bucket refill rate per second
tb := goralim.NewTokenBucket("key123", redisStore, 10, 5)// create HTTP server and setup a goralim middleware to put a rate limiter
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hey There this is a Request")
})rateLimitedHandler := goralim.RateLimiter(tb, handler)
http.ListenAndServe(":8080", rateLimitedHandler)
}
```## Contributions
feel free to create pull requests for the bugs and/or features. additionally, you can start working on any open issues that i've created. those are the priorities for next stable prod ready release. make sure you write and/or modify the test cases. thank you.
## License
Under [MIT](LICENSE) license