Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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) {
})
```