main.go 1.6 KB

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