Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vanng822/rlimiter
Simple redis rate limit for gin framework
https://github.com/vanng822/rlimiter
gin rate-limit rate-limiter rate-limiting redis
Last synced: 2 months ago
JSON representation
Simple redis rate limit for gin framework
- Host: GitHub
- URL: https://github.com/vanng822/rlimiter
- Owner: vanng822
- License: mit
- Created: 2019-02-16T08:18:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-07T18:17:39.000Z (8 months ago)
- Last Synced: 2024-10-08T15:09:37.401Z (3 months ago)
- Topics: gin, rate-limit, rate-limiter, rate-limiting, redis
- Language: Go
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rlimiter
Simple redis rate limit# example
```go
// applied only to endpoint login and POST
grbinder.BindVerb(group.Group("/login", rlimiter.GinRateLimit(
rlimiter.NewIPRateLimiter(
&rlimiter.Rate{Window: 10 * time.Second, Limit: 10},
"api.login"),
[]string{"POST"})),
&loginHandler{})```
```go
// Applied to any request method
limiter := rlimiter.GinRateLimit(
rlimiter.NewIPRateLimiter(
&rlimiter.Rate{Window: 1 * time.Minute, Limit: 10},
"api.hardwork"),
[]string{})r := gin.Default()
r.GET("/hardwork", limiter, func(c *gin.Context) {
})
r.POST("/hardwork", limiter, func(c *gin.Context) {
})
r.PUT("/hardwork", limiter, func(c *gin.Context) {
})
```