main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "eta/eta_mini_crm_ht/controllers"
  4. _ "eta/eta_mini_crm_ht/routers"
  5. "eta/eta_mini_crm_ht/services"
  6. "eta/eta_mini_crm_ht/utils"
  7. "fmt"
  8. "github.com/beego/beego/v2/core/logs"
  9. "github.com/beego/beego/v2/server/web"
  10. "github.com/beego/beego/v2/server/web/context"
  11. "runtime"
  12. "time"
  13. )
  14. func main() {
  15. if web.BConfig.RunMode == "dev" {
  16. web.BConfig.WebConfig.DirectoryIndex = true
  17. web.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
  18. }
  19. // 启动定时任务
  20. web.BConfig.WebConfig.AutoRender = false
  21. web.ErrorController(&controllers.ErrorController{})
  22. // 内存调整
  23. web.BConfig.MaxMemory = 1024 * 1024 * 128
  24. web.BConfig.RecoverFunc = Recover
  25. if utils.ENABLE_TASK == "true" {
  26. services.RepairImageData()
  27. }
  28. web.Run()
  29. }
  30. func Recover(ctx *context.Context, conf *web.Config) {
  31. if err := recover(); err != nil {
  32. if err == web.ErrAbort {
  33. return
  34. }
  35. if !web.BConfig.RecoverPanic {
  36. panic(err)
  37. }
  38. stack := ""
  39. msg := fmt.Sprintf("The request url is %v", ctx.Input.URL())
  40. stack += msg + "</br>"
  41. logs.Critical(msg)
  42. msg = fmt.Sprintf("The request data is %v", string(ctx.Input.RequestBody))
  43. stack += msg + "</br>"
  44. logs.Critical(msg)
  45. msg = fmt.Sprintf("Handler crashed with error %v", err)
  46. stack += msg + "</br>"
  47. logs.Critical(msg)
  48. for i := 1; ; i++ {
  49. _, file, line, ok := runtime.Caller(i)
  50. if !ok {
  51. break
  52. }
  53. logs.Critical(fmt.Sprintf("%s:%d", file, line))
  54. stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d</br>", file, line))
  55. }
  56. utils.ApiLog.Notice(utils.APPNAME + "崩了" + time.Now().Format("2006-01-02 15:04:05") + "<br/>" + stack)
  57. }
  58. return
  59. }