forked from Rafael010188/hexlet-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path32.go
More file actions
53 lines (41 loc) · 1.06 KB
/
32.go
File metadata and controls
53 lines (41 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"os"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/sirupsen/logrus"
)
func main() {
file, err := os.OpenFile(".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
logrus.Fatalf("error opening file: %v", err)
}
defer file.Close()
webApp := fiber.New(fiber.Config{
ReadBufferSize: 16 * 1024})
webApp.Get("/", func(c *fiber.Ctx) error {
return c.SendStatus(200)
})
// BEGIN (write your solution here) (write your solution here)
webApp.Use(logger.New(logger.Config{
Format: "${ID} ${method} ${path} - ${status}\n",
Output: file,
}))
webApp.Use(limiter.New(limiter.Config{
KeyGenerator: func(c *fiber.Ctx) string {
return c.IP()
},
Max: 1,
Expiration: 2 * time.Second,
}))
// END
webApp.Get("/foo", func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
})
webApp.Get("/bar", func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
})
logrus.Fatal(webApp.Listen(":8080"))
}