Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
ichunt_golang_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2b2334b1
authored
Mar 01, 2021
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
up
parent
2480b493
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
6 deletions
middleware/recovery.go
router/httpserver.go
middleware/recovery.go
View file @
2b2334b1
...
@@ -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
}
}
}
}
...
...
router/httpserver.go
View file @
2b2334b1
...
@@ -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
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment