Skip to content

Commit

Permalink
Merge pull request #29 from ccpwcn/dev
Browse files Browse the repository at this point in the history
新增获得当前代码所在函数名称的功能
  • Loading branch information
ccpwcn authored Oct 25, 2023
2 parents 1d4874f + 7bcf2c6 commit 1f1a2c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
- [x] UUID 高性能UUID
- Uuid 通用方法,自带缓冲池,不需要初始化,随时获得ID,多goroutine并发安全
- SimpleUuid 去除横线方法,自带缓冲池,不需要初始化,到处随时获得ID,多goroutine并发安全,推荐👍👍👍
- [x] 杂项
- RunFuncName 获得当前代码所在函数名

🍕🍕🍕更多使用方法请参见测试用例或代码注释,都非常简单易用。

Expand Down
11 changes: 11 additions & 0 deletions miscellaneous.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kgo

import "runtime"

// RunFuncName 获取正在运行的函数名,调用也也可以
func RunFuncName() string {
pc := make([]uintptr, 1)
runtime.Callers(2, pc)
f := runtime.FuncForPC(pc[0])
return f.Name()
}
11 changes: 11 additions & 0 deletions miscellaneous_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kgo

import (
"fmt"
"testing"
)

func TestGetRunFuncName(t *testing.T) {
name := RunFuncName()
fmt.Println(name)
}

0 comments on commit 1f1a2c8

Please sign in to comment.