• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jeffotoni / quick / 296

28 Mar 2025 12:12AM UTC coverage: 51.199% (+0.1%) from 51.093%
296

push

circleci

jeffotoni
Merge remote-tracking branch 'origin/docs/middleware'

update examples and docs

0 of 39 new or added lines in 12 files covered. (0.0%)

3 existing lines in 3 files now uncovered.

3074 of 6004 relevant lines covered (51.2%)

1667.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/example/middleware/limiter/basic/main.go
1
package main
2

3
import (
4
        "time"
5

6
        "github.com/jeffotoni/quick"
7
        "github.com/jeffotoni/quick/middleware/limiter"
8
)
9

10
func main() {
×
11
        q := quick.New()
×
12

×
13
        // Apply the rate limiter middleware
×
14
        q.Use(limiter.New(limiter.Config{
×
15
                // Maximum 10 requests allowed per IP
×
16
                Max: 10,
×
17
                // The limit resets after 5 seconds
×
18
                Expiration: 5 * time.Second,
×
19
                KeyGenerator: func(c *quick.Ctx) string {
×
20
                        // Uses the client's IP address as the key
×
21
                        return c.RemoteIP()
×
22
                },
×
23
                LimitReached: func(c *quick.Ctx) error {
×
24
                        c.Set("Content-Type", "application/json")
×
25
                        // The client should wait 10 seconds before retrying
×
26
                        c.Set("Retry-After", "10")
×
27
                        return c.Status(quick.StatusTooManyRequests).JSON(map[string]string{
×
28
                                "error":   "Too many requests",
×
29
                                "message": "You have exceeded the request limit. Please wait 1 second and try again.",
×
30
                                // Suggests a 1-second delay before retrying
×
31
                                "retry_after": "10s",
×
32
                        })
×
33
                },
×
34
        }))
35

36
        // Define a simple GET route
37
        q.Get("/", func(c *quick.Ctx) error {
×
NEW
38
                return c.Status(200).JSON(map[string]string{"msg": "Quick in action!"})
×
39
        })
×
40

41
        // Start the server on port 8080
42
        q.Listen(":8080")
×
43
}
44

45
// To test with Rate Limiter, use these curl commands:
46
// $ curl --location 'http://localhost:8080/'
47

48
//Script
49
// Function to test the Rate Limiter
50
// async function testRateLimiter() {
51

52
//     function delay(ms) {
53
//         return new Promise(resolve => setTimeout(resolve, ms));
54
//     }
55

56
//     for (let i = 0; i < 10; i++) {
57
//         pm.sendRequest("http://localhost:8080/", function (err, res) {
58
//             console.log(`Request ${i + 1}: Status - ${res.code} | Body - ${res.text()}`);
59
//         });
60

61
//         await delay(200);
62
//     }
63
// }
64
// testRateLimiter();
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc