22 lines
375 B
Go
22 lines
375 B
Go
package utils //nolint:revive
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
// Fnc prints the caller function name, file and line number.
|
|
func Fnc() {
|
|
pc, file, line, ok := runtime.Caller(1)
|
|
if !ok {
|
|
fmt.Println("unable to get caller")
|
|
return
|
|
}
|
|
fn := runtime.FuncForPC(pc)
|
|
name := "unknown"
|
|
if fn != nil {
|
|
name = fn.Name()
|
|
}
|
|
fmt.Printf("%s %s:%d <----\n", name, file, line)
|
|
}
|