Skip to content

Commit

Permalink
[FIX] test typo error (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas-ggd committed Jun 29, 2024
1 parent f87c1d8 commit 0b1c7e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,28 @@ func main() {
r := gin.Default()

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

// Call NewRateLimiter function from rrl package.
// First parameter is the Redis client.
// Second parameter is the rate (tokens per second).
// Third parameter is the maximum number of tokens.
limiter := rrl.NewRateLimiter(client, 1, 10)
// Fourth parameter is time duration, token refill is depending on x time interval
limiter := rrl.NewRateLimiter(client, 1, 10, 30*time.Second)

// Use RateLimiterMiddleware from rrl package and pass limiter.
// This middleware works for all routes in your application,
// including static files served when you open a web browser.
r.Use(rrl.RateLimiterMiddleware(limiter, 1))
r.Use(rrl.RateLimiterMiddleware(limiter))

r.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Welcome!"})
c.JSON(http.StatusOK, gin.H{"message": "Welcome!"})
})

// Using this way allows the RateLimiterMiddleware to work for only specific routes.
r.GET("/some", rrl.RateLimiterMiddleware(limiter, 1), func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Some!"})
r.GET("/some", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Some!"})
})

r.Run(":8080")
Expand Down
2 changes: 1 addition & 1 deletion limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func setupRedisClient() *redis.Client {

func TestRateLimiter_Allow(t *testing.T) {
client := setupRedisClient()
limiter := NewRateLimiter(client, 1, 5)
limiter := NewRateLimiter(client, 1, 5, time.Second)

tests := []struct {
name string
Expand Down

0 comments on commit 0b1c7e2

Please sign in to comment.