Refactor code

This commit is contained in:
wenxu12345
2022-01-15 18:36:40 +08:00
parent a2440a2e80
commit 7e13cc84c8
4 changed files with 158 additions and 69 deletions
+13
View File
@@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
"runtime"
"strconv"
"strings"
)
// copy a by b b->a
@@ -24,3 +25,15 @@ func printCallerNameAndLine() string {
pc, _, line, _ := runtime.Caller(2)
return runtime.FuncForPC(pc).Name() + "()@" + strconv.Itoa(line) + ": "
}
func GetSelfFuncName() string {
pc, _, _, _ := runtime.Caller(1)
return cleanUpFuncName(runtime.FuncForPC(pc).Name())
}
func cleanUpFuncName(funcName string) string {
end := strings.LastIndex(funcName, ".")
if end == -1 {
return ""
}
return funcName[end+1:]
}