Last active
December 24, 2015 18:08
-
-
Save kwmt/6840466 to your computer and use it in GitHub Desktop.
リフレクションを使って関数名を取得する。ついでに関数をコールする。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "reflect" | |
| "runtime" | |
| ) | |
| func f(n int) { | |
| fmt.Println(n) | |
| } | |
| func main() { | |
| fv := reflect.ValueOf(f) | |
| //関数名取得 | |
| fmt.Println(runtime.FuncForPC(fv.Pointer()).Name()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment