main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "eta_gn/eta_task/models"
  4. _ "eta_gn/eta_task/routers"
  5. "eta_gn/eta_task/services"
  6. "eta_gn/eta_task/services/alarm_msg"
  7. "eta_gn/eta_task/utils"
  8. "fmt"
  9. "github.com/beego/beego/v2/server/web"
  10. "runtime"
  11. "time"
  12. "github.com/beego/beego/v2/adapter/logs"
  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. // 初始化表数据入库
  21. models.AfterInitTable()
  22. go services.Task()
  23. //services.TaskInit()
  24. web.BConfig.RecoverFunc = Recover
  25. web.Run()
  26. }
  27. func Recover(ctx *context.Context, conf *web.Config) {
  28. if err := recover(); err != nil {
  29. if err == web.ErrAbort {
  30. return
  31. }
  32. if !web.BConfig.RecoverPanic {
  33. panic(err)
  34. }
  35. stack := ""
  36. msg := fmt.Sprintf("The request url is %v", ctx.Input.URL())
  37. stack += msg + "</br>"
  38. logs.Critical(msg)
  39. msg = fmt.Sprintf("The request data is %v", string(ctx.Input.RequestBody))
  40. stack += msg + "</br>"
  41. logs.Critical(msg)
  42. msg = fmt.Sprintf("Handler crashed with error %v", err)
  43. stack += msg + "</br>"
  44. logs.Critical(msg)
  45. for i := 1; ; i++ {
  46. _, file, line, ok := runtime.Caller(i)
  47. if !ok {
  48. break
  49. }
  50. logs.Critical(fmt.Sprintf("%s:%d", file, line))
  51. stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d</br>", file, line))
  52. }
  53. //go utils.SendEmail(utils.APPNAME+"崩了"+time.Now().Format("2006-01-02 15:04:05"), stack, utils.EmailSendToUsers)
  54. go alarm_msg.SendAlarmMsg(utils.APPNAME+"崩了"+time.Now().Format("2006-01-02 15:04:05")+"\n"+stack, 3)
  55. }
  56. return
  57. }