How does golang get the underlying type name?

how does golang get the underlying type name?

give an example:

func Hello(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "hello")
}

h := http.HandlerFunc(Hello)

http.HandleFunc("/hello", h)

here through reflection h I only get its name HandlerFunc , and I want to get h underlying type name Hello what should I do?

Jun.07,2022

is there any need to do this?

Hello function, compiled to be an address, what do you need the Hello flag for?

so I don't think I can get the Hello logo.

you can strings the compiled program to see if you can get the identifier.


you can get it with the following code:

runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name()
Menu