3
對於下面的代碼段(runnable via the Go Playground)在Go中獲取函數名稱時爲什麼會有「-fm」後綴?
package main
import (
"fmt"
"net/http"
"reflect"
"runtime"
)
type User struct{}
var u = &User{}
func (_ User) DummyHandler(w http.ResponseWriter, r *http.Request) {}
func funcName(i interface{}) {
p := reflect.ValueOf(i).Pointer()
n := runtime.FuncForPC(p).Name()
fmt.Println(n)
}
func main() {
funcName(u.DummyHandler)
}
輸出爲main.(User).DummyHandler-fm
。
爲什麼函數名稱末尾有-fm
?