调用函数:
func FuncForPC(pc uintptr) *Func {
func Caller(skip int) Frame {
例子:
package main
import (
"fmt"
"runtime"
)
func main () {
funcName, file, line, ok := runtime.Caller(0)
if ok {
fmt.Println("file:", file, " func:", runtime.FuncForPC(funcName).Name(), " line:", line)
}
}
执行结果:
file: /root/use.go func: main.main line: 23