Skip to content

Instantly share code, notes, and snippets.

@kwmt
Last active December 24, 2015 18:08
Show Gist options
  • Select an option

  • Save kwmt/6840466 to your computer and use it in GitHub Desktop.

Select an option

Save kwmt/6840466 to your computer and use it in GitHub Desktop.
リフレクションを使って関数名を取得する。ついでに関数をコールする。
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