This commit is contained in:
aozhiwei 2024-03-24 08:43:31 +08:00
parent 583a9d2358
commit 61a612b594

View File

@ -9,6 +9,7 @@ import (
"os"
"reflect"
"time"
"runtime"
)
func GetDaySeconds(seconds int64, timeZone int64) int64 {
@ -209,3 +210,26 @@ func AppendSlice[T any](s *[]T, val T) {
func GetTypeName(v interface{}) string {
return reflect.TypeOf(v).String()
}
func PrintCallStack() {
// 获取当前函数的调用者信息
pc, file, line, ok := runtime.Caller(1)
if !ok {
fmt.Println("runtime.Caller error")
return
}
funcName := runtime.FuncForPC(pc).Name()
fmt.Printf("Function: %s\nFile: %s\nLine: %d\n", funcName, file, line)
// 使用Stack打印完整的调用栈信息可以用于debug
buf := make([]byte, 1024)
for {
n := runtime.Stack(buf, false)
if n < len(buf) {
break
}
buf = make([]byte, 2*len(buf))
}
fmt.Println(string(buf))
}