main.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. _ "eta/eta_index_lib/routers"
  4. "eta/eta_index_lib/services/alarm_msg"
  5. "eta/eta_index_lib/utils"
  6. "fmt"
  7. "github.com/beego/beego/v2/adapter/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. web.BConfig.RecoverFunc = Recover
  19. web.Run()
  20. }
  21. func Recover(ctx *context.Context, conf *web.Config) {
  22. if err := recover(); err != nil {
  23. if err == web.ErrAbort {
  24. return
  25. }
  26. if !web.BConfig.RecoverPanic {
  27. panic(err)
  28. }
  29. stack := ""
  30. msg := fmt.Sprintf("The request url is %v", ctx.Input.URL())
  31. stack += msg + "</br>"
  32. logs.Critical(msg)
  33. msg = fmt.Sprintf("The request data is %v", string(ctx.Input.RequestBody))
  34. stack += msg + "</br>"
  35. logs.Critical(msg)
  36. msg = fmt.Sprintf("Handler crashed with error %v", err)
  37. stack += msg + "</br>"
  38. logs.Critical(msg)
  39. for i := 1; ; i++ {
  40. _, file, line, ok := runtime.Caller(i)
  41. if !ok {
  42. break
  43. }
  44. logs.Critical(fmt.Sprintf("%s:%d", file, line))
  45. stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d</br>", file, line))
  46. }
  47. //go utils.SendEmail(utils.APP_NAME_CN+"崩了"+time.Now().Format("2006-01-02 15:04:05"), stack, utils.EmailSendToUsers)
  48. go alarm_msg.SendAlarmMsg(utils.APP_NAME_CN+"崩了"+time.Now().Format("2006-01-02 15:04:05")+"<br/>"+stack, 3)
  49. }
  50. return
  51. }