1 Star 0 Fork 0

exlimit/tegola

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mycaller.go 719 Bytes
一键复制 编辑 原始数据 按行查看 历史
package list
import (
"fmt"
"path/filepath"
"runtime"
)
// MyCallerFileLine returns the FileLine of the caller of the function that called it :)
func MyCallerFileLine() string {
// we get the callers as uintptrs - but we just need 1
fpcs := make([]uintptr, 1)
// skip 3 levels to get to the caller of whoever called Caller()
n := runtime.Callers(3, fpcs)
if n == 0 {
return "n/a" // proper error her would be better
}
// get the info of the actual function that's in the pointer
fun := runtime.FuncForPC(fpcs[0] - 1)
if fun == nil {
return "n/a"
}
// return its name
filename, line := fun.FileLine(fpcs[0] - 1)
filename = filepath.Base(filename)
return fmt.Sprintf("%v:%v", filename, line)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/exlimit/tegola.git
git@gitee.com:exlimit/tegola.git
exlimit
tegola
tegola
v0.10.4

搜索帮助