Skip to content

aitay721822/gin-redis-ratelimiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gin-redis-ratelimiter

This is an example about using Redis + Token Bucket algorithm for Rate Limiting on Gin Framework.

Usage

 client := redis.NewClient(&redis.Options{
  Addr: "localhost:6379",
  Password: "",
  DB: 0,
 })

lm := ginredisratelimiter.NewRedisRateLimiter(ctx, "ping", time.Minute, 10, client)

r.GET("/ping", lm.Middleware(), func(c *gin.Context) {
  c.JSON(200, gin.H{
   "message": "pong",
  })
})

That means the URI /ping only allow 10 request per minute by IP Address.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages