如何从堆栈跟踪中删除绝对路径? [重复]

This question already has an answer here:

How can I remove absolute paths from the stack trace?

For example, now:

main.main()
    /home/userName/WORKSPACE/temp/mvps/main.go:16 +0xb2

And I want it to be something like this:

main.main()
    main.go:16 +0xb2
</div>

To remove the GOPATH prefix, add the following flags when you run go build (ref):

go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH ...

If GOPATH is not set in your environment, $(go env GOPATH) is still likely to work (thanks to Flimzy for pointing this out):

go build -gcflags=-trimpath=$(go env GOPATH) -asmflags=-trimpath=$(go env GOPATH) ...