forked from jykuo-love-shiritori/twp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (58 loc) · 1.55 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
package main
import (
"context"
"net/http"
"os"
"os/signal"
"time"
"github.com/jykuo-love-shiritori/twp/db"
"github.com/jykuo-love-shiritori/twp/minio"
"github.com/jykuo-love-shiritori/twp/pkg/boot"
"github.com/jykuo-love-shiritori/twp/pkg/common"
"github.com/jykuo-love-shiritori/twp/pkg/constants"
"github.com/jykuo-love-shiritori/twp/pkg/image"
"github.com/jykuo-love-shiritori/twp/pkg/router"
"go.uber.org/zap"
"github.com/labstack/echo/v4"
)
func main() {
e := echo.New()
logger, err := zap.NewProduction()
if err != nil {
e.Logger.Fatal(err)
}
RegisterLogger(e, logger)
db, err := db.NewDB()
if err != nil {
e.Logger.Fatal(err)
}
mc, err := minio.NewMINIO()
if err != nil {
e.Logger.Fatal(err)
}
err = boot.CheckAdminAccount(db, context.Background())
if err != nil {
e.Logger.Fatal(err)
}
RegisterFrontend(e)
image.RegisterImage(e, mc, logger.Sugar())
router.RegisterApi(e, db, mc, logger.Sugar())
if common.IsEnv(constants.DEV) {
router.RegisterDocs(e)
}
go func() {
if err := e.Start(":" + os.Getenv("TWP_PORT")); err != nil && err != http.ErrServerClosed {
e.Logger.Fatal("shutting down the server")
}
}()
// Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds.
// Use a buffered channel to avoid missing signals as recommended for signal.Notify
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
}
}