鉴于一个功能,是否有可能得到它的名字?说:
func foo() {
}
func GetFunctionName(i interface{}) string {
// ...
}
func main() {
// Will print "name: foo"
fmt.Println("name:", GetFunctionName(foo))
}
Run Code Online (Sandbox Code Playgroud)
我被告知runtime.FuncForPC会有所帮助,但我不明白如何使用它.
有可能在golang中获取有关调用函数的信息吗?例如,如果我有
func foo() {
//Do something
}
func main() {
foo()
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能是foo被称为从main?
我能用其他语言(例如在C#中我只需要使用CallerMemberNameclass属性)