From 0b1c7e253e66c8fc556c212583b1ee5be67a1672 Mon Sep 17 00:00:00 2001 From: Nicolas-ggd Date: Sat, 29 Jun 2024 11:16:52 +0400 Subject: [PATCH] [FIX] test typo error (#9) --- README.md | 13 +++++++------ limiter_test.go | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fc7d107..21df7c4 100644 --- a/README.md +++ b/README.md @@ -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") diff --git a/limiter_test.go b/limiter_test.go index cd1a3d5..4bd8d3b 100644 --- a/limiter_test.go +++ b/limiter_test.go @@ -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