Commit 26198d5b by 杨树贤

caller函数修改

parent 1dadd8a3
Showing with 7 additions and 5 deletions
...@@ -5,18 +5,20 @@ import "runtime" ...@@ -5,18 +5,20 @@ import "runtime"
type Caller struct { type Caller struct {
FileName string FileName string
FileLine int FileLine int
FunctionName string
} }
//获取上级调用者 //获取上级调用者
//2代表上级,3代表上上级 //2代表上级,3代表上上级
func getCaller() Caller { func GetCaller(skip int) Caller {
pc, _, _, _ := runtime.Caller(2) pc, _, _, _ := runtime.Caller(skip)
caller := runtime.FuncForPC(pc) caller := runtime.FuncForPC(pc)
_, fileLine := caller.FileLine(pc) fileName, fileLine := caller.FileLine(pc)
name := caller.Name() functionName := caller.Name()
return Caller{ return Caller{
FileName: name, FunctionName: functionName,
FileName: fileName,
FileLine: fileLine, 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