reflect.ValueOf().Pointer() と runtime.FuncForPC を組み合わせる
func FunctionName(i any) string {
if reflect.TypeOf(i).Kind() == reflect.Func {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}
return ""
}Search
reflect.ValueOf().Pointer() と runtime.FuncForPC を組み合わせる
func FunctionName(i any) string {
if reflect.TypeOf(i).Kind() == reflect.Func {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}
return ""
}