-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (54 loc) · 1.19 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
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/encryptcookie"
"github.com/gofiber/fiber/v2/middleware/favicon"
"github.com/gofiber/template/django"
"meta-go/db"
"meta-go/router"
"meta-go/util/middleware"
_ "meta-go/util/template"
)
func main() {
app := fiber.New(fiber.Config{
AppName: "meta-go",
BodyLimit: 1024 * 1024 * 20,
Views: django.New("./template", ".html"),
})
app.Static("/static", "./static")
app.Use(
middleware.Gate(),
encryptcookie.New(encryptcookie.Config{
Key: "vtDs1VZzSZ+flREhrrybKFBY8j1K8g0NyvRmv9+8MRA=",
}),
favicon.New(favicon.Config{
File: "./static/favicon.ico",
}),
middleware.UserAuth(),
)
db.Init()
router.Register(app)
start(app)
}
func start(app *fiber.App) {
if err := app.Listen(":9000"); err != nil {
log.Panic(err)
}
}
func gracefulStart(app *fiber.App) {
go func() {
if err := app.Listen(":9000"); err != nil {
log.Panic(err)
}
}()
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
_ = <-c
log.Println("Gracefully shutting down...")
_ = app.Shutdown()
log.Println("Shutdown successfully.")
}