Standard library / runtime
runtime.Func.Name()
Returns the function name from runtime symbol metadata. It is useful for diagnostics, not stable application identifiers. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (f *Func) Name() stringReturn Value
string
Name of the compiled function.
Working Example
Example Snippetgo
package main
import ( "fmt" "runtime")
func main() { pc, _, _, _ := runtime.Caller(0) fmt.Println(runtime.FuncForPC(pc).Name() == "main.main")}