Commit 2b2334b1 by 孙龙

up

parent 2480b493
Showing with 7 additions and 6 deletions
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
common "ichunt_golang/app/common/function"
"ichunt_golang/util" "ichunt_golang/util"
"github.com/ichunt2019/cfg/lib" "github.com/ichunt2019/cfg/lib"
"runtime/debug" "runtime/debug"
...@@ -12,20 +13,21 @@ import ( ...@@ -12,20 +13,21 @@ import (
// RecoveryMiddleware捕获所有panic,并且返回错误信息 // RecoveryMiddleware捕获所有panic,并且返回错误信息
func RecoveryMiddleware() gin.HandlerFunc { func RecoveryMiddleware() gin.HandlerFunc {
return func(c *gin.Context) { 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() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
//先做一下日志记录 //先做一下日志记录
fmt.Println(string(debug.Stack())) //fmt.Println(string(debug.Stack()))
util.ComLogNotice(c, "_com_panic", map[string]interface{}{ util.ComLogNotice(c, "_com_panic", map[string]interface{}{
"error": fmt.Sprint(err), "error": fmt.Sprint(err),
"stack": string(debug.Stack()), "stack": string(debug.Stack()),
}) })
if lib.Instance("proxy").GetString("base.debug_mode") != "debug" { 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 return
} else { } else {
ResponseError(c, 500, errors.New(fmt.Sprint(err))) common.Output(c,500,"内部错误",errors.New(fmt.Sprint(err)))
return return
} }
} }
......
...@@ -2,7 +2,6 @@ package router ...@@ -2,7 +2,6 @@ package router
import ( import (
"context" "context"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
cfg "github.com/ichunt2019/cfg/lib" cfg "github.com/ichunt2019/cfg/lib"
"ichunt_golang/middleware" "ichunt_golang/middleware"
...@@ -20,7 +19,7 @@ var ( ...@@ -20,7 +19,7 @@ var (
func HttpServerRun() { func HttpServerRun() {
//debug release test 开发使用debug模式 //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")) gin.SetMode(cfg.Instance("proxy").GetString("base.debug_mode"))
r := InitRouter(middleware.RequestLog(),middleware.RecoveryMiddleware()) 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