I need to figure out if a reflect.Value that is a function (Func) has a 
receiver (i.e. it is a method) or if the Func is just a plain function with 
no receiver in its signature.

Here's what I came up (which does appear to solve the question in the 
limited cases I've tested)... but I'm wondering if there is a faster and/or 
guaranteed reliable approach that doesn't feel quite so hacky with the 
string comparison:

import (
"runtime"
"reflect"
...
)
...
func getFunctionName(fun reflect.Value) string {
       return runtime.FuncForPC(fun.Pointer()).Name()
}

func main() {

isMethod := getFunctionName(v) == "reflect.methodValueCall"
...
}

Is there a better way?  Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to