-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (46 loc) · 1.65 KB
/
main.go
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
54
55
56
57
58
package main
import (
"fmt"
"time"
"github.com/gofiber/fiber/v2"
"github.com/owlsome-official/zlogtime"
"github.com/rs/zerolog"
)
var (
timeTracker zlogtime.ZLogTime = zlogtime.New()
timeTrackerWithConfig zlogtime.ZLogTime = zlogtime.New(zlogtime.Config{LogLevel: zerolog.DebugLevel.String()})
)
func main() {
app := fiber.New(fiber.Config{DisableStartupMessage: true})
app.Get("/get_data_from_db", Handler) // GET http://localhost:8000/get_data_from_db
fmt.Println("Listening on http://localhost:8000")
fmt.Println("Try to send a request :D")
go app.Listen(":8000")
customApp := fiber.New(fiber.Config{DisableStartupMessage: true})
customApp.Get("/one", HandlerBySecond(1)) // GET http://localhost:8000/one
customApp.Get("/onepointfive", HandlerBySecond(1.5)) // GET http://localhost:8000/onepointfive
customApp.Get("/three", HandlerBySecond(3)) // GET http://localhost:8000/three
customApp.Listen(":8001")
}
func Handler(c *fiber.Ctx) error {
StopFor(0.02)
return c.SendString("It's took 20ms!")
}
func StopFor(sec float64) {
defer timeTracker.TimeTrack("Stop for "+fmt.Sprintf("%v", sec)+"s", time.Now())
time.Sleep(time.Duration(sec*1000) * time.Millisecond)
}
// ===========================
// CUSTOM APP WITH DEBUG LEVEL
// ===========================
func HandlerBySecond(sec float64) fiber.Handler {
return func(c *fiber.Ctx) error {
DebugStopFor(sec)
return c.SendString("Watch your app logs!")
}
}
func DebugStopFor(sec float64) {
defer timeTrackerWithConfig.TimeTrack("Stop for "+fmt.Sprintf("%v", sec)+"s", time.Now())
time.Sleep(time.Duration(sec*1000) * time.Millisecond)
}
// ===========================