Closed
Description
I was playing with a method that wants to print the file:line of the caller. runtime.Caller(1)
seems like it should do the trick, but I get ':2'. If I call runtime.Caller(2)
instead it seems to work, but I am reluctant to depend on that.
It looks like this has to do with being an interface method: https://play.golang.org/p/I5XPdWR_O0
Is there a generic way to get the actual caller, safely, in all cases?
- What version of Go are you using (
go version
)?
go version go1.6.1 linux/amd64
- What operating system and processor architecture are you using (
go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/thockin/src/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"