-
-
Notifications
You must be signed in to change notification settings - Fork 472
/
Copy pathmain.go
45 lines (35 loc) · 949 Bytes
/
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
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/gofiber/fiber/v2"
)
const idleTimeout = 5 * time.Second
func main() {
app := fiber.New(fiber.Config{
IdleTimeout: idleTimeout,
})
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello world!")
})
// Listen from a different goroutine
go func() {
if err := app.Listen(":3000"); err != nil {
log.Panic(err)
}
}()
c := make(chan os.Signal, 1) // Create channel to signify a signal being sent
signal.Notify(c, os.Interrupt, syscall.SIGTERM) // When an interrupt or termination signal is sent, notify the channel
_ = <-c // This blocks the main thread until an interrupt is received
fmt.Println("Gracefully shutting down...")
_ = app.Shutdown()
fmt.Println("Running cleanup tasks...")
// Your cleanup tasks go here
// db.Close()
// redisConn.Close()
fmt.Println("Fiber was successful shutdown.")
}