-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.go
54 lines (47 loc) · 1.23 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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"log"
"luma-api/common"
"luma-api/middleware"
"net/http"
"runtime/debug"
)
func main() {
common.SetupLogger()
common.Logger.Info("Luma-API started")
if common.DebugEnabled {
common.Logger.Info("running in debug mode")
gin.SetMode(gin.ReleaseMode)
}
if common.PProfEnabled {
common.SafeGoroutine(func() {
log.Println(http.ListenAndServe("0.0.0.0:8005", nil))
})
common.Logger.Info("running in pprof")
}
common.InitTemplate()
common.SafeGoroutine(func() {
StartAllKeepAlive()
})
// Initialize HTTP server
server := gin.New()
server.Use(middleware.RequestId())
server.Use(gin.CustomRecovery(func(c *gin.Context, err any) {
common.Logger.Error(fmt.Sprintf("panic detected: %v, stack: %s", err, string(debug.Stack())))
c.JSON(http.StatusInternalServerError, gin.H{
"error": gin.H{
"message": fmt.Sprintf("Panic detected, error: %v. Please contact site admin", err),
"type": "api_panic",
},
})
}))
server.Use(middleware.GinzapWithConfig())
RegisterRouter(server)
common.Logger.Info("Start: 0.0.0.0:" + common.Port)
err := server.Run(":" + common.Port)
if err != nil {
common.Logger.Fatal("failed to start HTTP server: " + err.Error())
}
}