main.go 1.6 KB

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