main.go 1.5 KB

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