()
| 11 | ) |
| 12 | |
| 13 | func main() { |
| 14 | common.SetupLogger() |
| 15 | common.Logger.Info("Luma-API started") |
| 16 | |
| 17 | if common.DebugEnabled { |
| 18 | common.Logger.Info("running in debug mode") |
| 19 | gin.SetMode(gin.ReleaseMode) |
| 20 | } |
| 21 | if common.PProfEnabled { |
| 22 | common.SafeGoroutine(func() { |
| 23 | log.Println(http.ListenAndServe("0.0.0.0:8005", nil)) |
| 24 | }) |
| 25 | common.Logger.Info("running in pprof") |
| 26 | } |
| 27 | common.InitTemplate() |
| 28 | |
| 29 | common.SafeGoroutine(func() { |
| 30 | StartAllKeepAlive() |
| 31 | }) |
| 32 | |
| 33 | // Initialize HTTP server |
| 34 | server := gin.New() |
| 35 | server.Use(middleware.RequestId()) |
| 36 | server.Use(gin.CustomRecovery(func(c *gin.Context, err any) { |
| 37 | common.Logger.Error(fmt.Sprintf("panic detected: %v, stack: %s", err, string(debug.Stack()))) |
| 38 | c.JSON(http.StatusInternalServerError, gin.H{ |
| 39 | "error": gin.H{ |
| 40 | "message": fmt.Sprintf("Panic detected, error: %v. Please contact site admin", err), |
| 41 | "type": "api_panic", |
| 42 | }, |
| 43 | }) |
| 44 | })) |
| 45 | server.Use(middleware.GinzapWithConfig()) |
| 46 | |
| 47 | RegisterRouter(server) |
| 48 | |
| 49 | common.Logger.Info("Start: 0.0.0.0:" + common.Port) |
| 50 | err := server.Run(":" + common.Port) |
| 51 | if err != nil { |
| 52 | common.Logger.Fatal("failed to start HTTP server: " + err.Error()) |
| 53 | } |
| 54 | } |
nothing calls this directly
no test coverage detected