mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-07 19:50:24 +08:00
30 lines
543 B
Go
30 lines
543 B
Go
package nano
|
|
|
|
import (
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
func getFuncNameWithSkip(n int) string {
|
|
pc, _, _, ok := runtime.Caller(n)
|
|
if !ok {
|
|
return ""
|
|
}
|
|
fullname := runtime.FuncForPC(pc).Name()
|
|
i := strings.LastIndex(fullname, ".") + 1
|
|
if i <= 0 || i >= len(fullname) {
|
|
return fullname
|
|
}
|
|
return fullname[i:]
|
|
}
|
|
|
|
// getThisFuncName 获取正在执行的函数名
|
|
func getThisFuncName() string {
|
|
return getFuncNameWithSkip(1)
|
|
}
|
|
|
|
// getCallerFuncName 获取调用者函数名
|
|
func getCallerFuncName() string {
|
|
return getFuncNameWithSkip(2)
|
|
}
|