Commit 26198d5b by 杨树贤

caller函数修改

parent 1dadd8a3
Showing with 10 additions and 8 deletions
......@@ -3,20 +3,22 @@ package util
import "runtime"
type Caller struct {
FileName string
FileLine int
FileName string
FileLine int
FunctionName string
}
//获取上级调用者
//2代表上级,3代表上上级
func getCaller() Caller {
pc, _, _, _ := runtime.Caller(2)
func GetCaller(skip int) Caller {
pc, _, _, _ := runtime.Caller(skip)
caller := runtime.FuncForPC(pc)
_, fileLine := caller.FileLine(pc)
name := caller.Name()
fileName, fileLine := caller.FileLine(pc)
functionName := caller.Name()
return Caller{
FileName: name,
FileLine: fileLine,
FunctionName: functionName,
FileName: fileName,
FileLine: fileLine,
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment