代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。