File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ import (
12
12
"net/http"
13
13
"net/http/httputil"
14
14
"net/url"
15
+ "reflect"
16
+ "runtime"
17
+ "runtime/debug"
15
18
"strconv"
16
19
"strings"
17
20
"time"
@@ -24,7 +27,19 @@ import (
24
27
//
25
28
// 将需要修改上游响应的处理器包装成一个 gin.HandlerFunc 处理器
26
29
func responseModifyCreater (proxy * httputil.ReverseProxy , modifyResponseFN func (rw * http.Response ) error ) gin.HandlerFunc {
27
- proxy .ModifyResponse = modifyResponseFN
30
+ funcPtr := reflect .ValueOf (modifyResponseFN ).Pointer ()
31
+ funcName := strings .ReplaceAll (runtime .FuncForPC (funcPtr ).Name (), "-fm" , "" )
32
+ logging .Debugf ("创建响应修改处理器:%s" , funcName )
33
+
34
+ proxy .ModifyResponse = func (rw * http.Response ) error {
35
+ defer func () {
36
+ if r := recover (); r != nil {
37
+ logging .Errorf ("%s 发生 panic:%s\n %s" , funcName , r , string (debug .Stack ()))
38
+ }
39
+ }()
40
+ return modifyResponseFN (rw )
41
+ }
42
+
28
43
return func (ctx * gin.Context ) {
29
44
proxy .ServeHTTP (ctx .Writer , ctx .Request )
30
45
}
You can’t perform that action at this time.
0 commit comments