Commit 2b2334b1 by 孙龙

up

parent 2480b493
Showing with 7 additions and 6 deletions
......@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
common "ichunt_golang/app/common/function"
"ichunt_golang/util"
"github.com/ichunt2019/cfg/lib"
"runtime/debug"
......@@ -12,20 +13,21 @@ import (
// RecoveryMiddleware捕获所有panic,并且返回错误信息
func RecoveryMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
fmt.Println(lib.Instance("proxy").GetString("base.debug_mode"))
//fmt.Println(lib.Instance("proxy").GetString("base.debug_mode"))
defer func() {
if err := recover(); err != nil {
//先做一下日志记录
fmt.Println(string(debug.Stack()))
//fmt.Println(string(debug.Stack()))
util.ComLogNotice(c, "_com_panic", map[string]interface{}{
"error": fmt.Sprint(err),
"stack": string(debug.Stack()),
})
if lib.Instance("proxy").GetString("base.debug_mode") != "debug" {
ResponseError(c, 500, errors.New("内部错误"))
//ResponseError(c, 500, errors.New("内部错误"))
common.Output(c,500,"内部错误",nil)
return
} else {
ResponseError(c, 500, errors.New(fmt.Sprint(err)))
common.Output(c,500,"内部错误",errors.New(fmt.Sprint(err)))
return
}
}
......
......@@ -2,7 +2,6 @@ package router
import (
"context"
"fmt"
"github.com/gin-gonic/gin"
cfg "github.com/ichunt2019/cfg/lib"
"ichunt_golang/middleware"
......@@ -20,7 +19,7 @@ var (
func HttpServerRun() {
//debug release test 开发使用debug模式
fmt.Println(cfg.Instance("proxy").GetString("base.debug_mode"))
//fmt.Println(cfg.Instance("proxy").GetString("base.debug_mode"))
gin.SetMode(cfg.Instance("proxy").GetString("base.debug_mode"))
r := InitRouter(middleware.RequestLog(),middleware.RecoveryMiddleware())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment