This commit is contained in:
白茶清欢 2024-09-30 15:54:20 +08:00
parent 02cdc3c792
commit e52d67cfe3

View File

@ -11,6 +11,8 @@ import (
"fmt"
"net/http"
"runtime"
"strconv"
"strings"
"time"
"git.zhangdeman.cn/zhangdeman/exception"
@ -109,11 +111,29 @@ 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(),
"u_e_data": data,