1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package main
- import (
- "eta_gn/eta_task/models"
- _ "eta_gn/eta_task/routers"
- "eta_gn/eta_task/services"
- "eta_gn/eta_task/services/alarm_msg"
- "eta_gn/eta_task/utils"
- "fmt"
- "github.com/beego/beego/v2/server/web"
- "runtime"
- "time"
- "github.com/beego/beego/v2/adapter/logs"
- "github.com/beego/beego/v2/server/web/context"
- )
- func main() {
- if web.BConfig.RunMode == "dev" {
- web.BConfig.WebConfig.DirectoryIndex = true
- web.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
- }
- // 初始化表数据入库
- models.AfterInitTable()
- go services.Task()
- //services.TaskInit()
- web.BConfig.RecoverFunc = Recover
- web.Run()
- }
- func Recover(ctx *context.Context, conf *web.Config) {
- if err := recover(); err != nil {
- if err == web.ErrAbort {
- return
- }
- if !web.BConfig.RecoverPanic {
- panic(err)
- }
- stack := ""
- msg := fmt.Sprintf("The request url is %v", ctx.Input.URL())
- stack += msg + "</br>"
- logs.Critical(msg)
- msg = fmt.Sprintf("The request data is %v", string(ctx.Input.RequestBody))
- stack += msg + "</br>"
- logs.Critical(msg)
- msg = fmt.Sprintf("Handler crashed with error %v", err)
- stack += msg + "</br>"
- logs.Critical(msg)
- for i := 1; ; i++ {
- _, file, line, ok := runtime.Caller(i)
- if !ok {
- break
- }
- logs.Critical(fmt.Sprintf("%s:%d", file, line))
- stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d</br>", file, line))
- }
- //go utils.SendEmail(utils.APPNAME+"崩了"+time.Now().Format("2006-01-02 15:04:05"), stack, utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg(utils.APPNAME+"崩了"+time.Now().Format("2006-01-02 15:04:05")+"\n"+stack, 3)
- }
- return
- }
|