Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imtoori/gin-redis-ip-limiter
Simple gin middleware ip limiter
https://github.com/imtoori/gin-redis-ip-limiter
gin-gonic go golang redis
Last synced: 28 days ago
JSON representation
Simple gin middleware ip limiter
- Host: GitHub
- URL: https://github.com/imtoori/gin-redis-ip-limiter
- Owner: imtoori
- Created: 2018-03-19T22:38:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-21T09:30:07.000Z (over 6 years ago)
- Last Synced: 2024-02-14T19:32:45.971Z (9 months ago)
- Topics: gin-gonic, go, golang, redis
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 26
- Watchers: 3
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-gin - imtoori/gin-redis-ip-limiter
README
## Description
It works with redis. It's pluggable and all you need is a redis client for every limiter.
It limits path access based on client ip-address.It's inspired by this article https://engagor.github.io/blog/2017/05/02/sliding-window-rate-limiter-redis/.
It uses this golang redis library https://github.com/go-redis/redis.
## Installation
Just run
`go get -u github.com/Salvatore-Giordano/gin-redis-ip-limiter/`
## Example
```go
package mainimport (
"github.com/Salvatore-Giordano/gin-redis-ip-limiter"
"github.com/gin-gonic/gin"
)func main() {
r := gin.Default()
r.Use(iplimiter.NewRateLimiterMiddleware(redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 1,
}), "general", 200, 60*time.Second))
// ...
r.Run(":8080")
}
```
**Key**: this is the key used to save data on redis. Data are saved as ip:key.**Limit**: number of request to accept.
**SlidingWindow**: duration of the sliding window to consider.