forked from xinliangnote/go-gin-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
110d9da
commit fd2b24a
Showing
4 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,5 @@ const ( | |
ErrorNotifyUser = "xinliangnote@163.com" | ||
|
||
// 告警开关 1=开通 -1=关闭 | ||
ErrorNotifyOpen = 1 | ||
ErrorNotifyOpen = -1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package exception | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
"go-gin-api/app/config" | ||
"go-gin-api/app/util" | ||
"runtime/debug" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func SetUp() gin.HandlerFunc { | ||
|
||
return func(c *gin.Context) { | ||
defer func() { | ||
if err := recover(); err != nil { | ||
subject := fmt.Sprintf("[Panic - %s] 项目出错了!", config.AppName) | ||
body := fmt.Sprintf("<b>错误时间:%s\n Runtime:\n</b>%s",time.Now().Format("2006/01/02 - 15:04:05"), string(debug.Stack())) | ||
bodyHtml := "" | ||
for _,v := range strings.Split(body, "\n") { | ||
bodyHtml += v + "<br>" | ||
} | ||
_ = util.SendMail(config.ErrorNotifyUser, subject, bodyHtml) | ||
|
||
utilGin := util.Gin{Ctx:c} | ||
utilGin.Response(500, "系统异常,请联系管理员!", nil) | ||
} | ||
}() | ||
c.Next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters