()
| 10 | ) |
| 11 | |
| 12 | func 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 | } |
nothing calls this directly
no test coverage detected