MCPcopy Create free account
hub / github.com/BryanMwangi/pine / main

Function main

Examples/RateLimitExample/main.go:12–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12func main() {
13 app := pine.New()
14
15 // create a new rate limit middleware
16 app.Use(limiter.New(
17 limiter.Config{
18 MaxRequests: 5,
19 Window: 30 * time.Second,
20 ShowHeader: true,
21 KeyGen: func(c *pine.Ctx) string { return c.IP() },
22 Handler: func(c *pine.Ctx) error {
23 ip := c.IP()
24 fmt.Println("too many requests from IP: " + ip)
25 return c.SendStatus(429)
26 },
27 },
28 ))
29
30 app.Get("/hello", func(c *pine.Ctx) error {
31 return c.SendString("Hello World!")
32 })
33
34 log.Fatal(app.Start(":3001"))
35}

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
NewFunction · 0.92
UseMethod · 0.80
IPMethod · 0.80
SendStatusMethod · 0.80
SendStringMethod · 0.80
GetMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected