From e52d67cfe36a319bb76279060f33d00c44835fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 30 Sep 2024 15:54:20 +0800 Subject: [PATCH] update --- response/response.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/response/response.go b/response/response.go index 80e690a..2040f6e 100644 --- a/response/response.go +++ b/response/response.go @@ -11,6 +11,8 @@ import ( "fmt" "net/http" "runtime" + "strconv" + "strings" "time" "git.zhangdeman.cn/zhangdeman/exception" @@ -109,10 +111,28 @@ func SendWithException(ctx *gin.Context, e exception.IException, data any) { e = exception.NewSuccess(data) } if !define.GetHttpHandleConfig().DisableDebugStackOutput { - pc, file, line, ok := runtime.Caller(1) - if ok { - fmt.Println(runtime.FuncForPC(pc).Name(), file, line) + pcs := make([]uintptr, 128) + n := runtime.Callers(2, pcs) + + frames := runtime.CallersFrames(pcs[:n]) + + var sb strings.Builder + for { + frame, more := frames.Next() + + sb.WriteString(frame.Function) + sb.WriteByte('\n') + sb.WriteByte('\t') + sb.WriteString(frame.File) + sb.WriteByte(':') + sb.WriteString(strconv.Itoa(frame.Line)) + sb.WriteByte('\n') + + if !more { + break + } } + fmt.Println(sb.String()) } outputData := map[string]any{ "e_data": e.GetData(),