1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-08 12:10:23 +08:00

finish base

This commit is contained in:
源文雨
2023-10-10 14:10:13 +09:00
parent 6c87546b44
commit 3dbb8d7b34
13 changed files with 427 additions and 0 deletions

34
helper.go Normal file
View File

@@ -0,0 +1,34 @@
package nano
import (
"runtime"
"strings"
)
// getCurrentFuncName 获取当前函数名
func getCurrentFuncName() string {
pc, _, _, ok := runtime.Caller(1)
if !ok {
return ""
}
fullname := runtime.FuncForPC(pc).Name()
i := strings.LastIndex(fullname, ".") + 1
if i <= 0 || i >= len(fullname) {
return fullname
}
return fullname[i:]
}
// getCallerFuncName 获取调用者函数名
func getCallerFuncName() string {
pc, _, _, ok := runtime.Caller(2)
if !ok {
return ""
}
fullname := runtime.FuncForPC(pc).Name()
i := strings.LastIndex(fullname, ".") + 1
if i <= 0 || i >= len(fullname) {
return fullname
}
return fullname[i:]
}