如何解决在go中删除跟踪中的模块路径
我需要删除跟踪中与导入模块相对应的绝对路径。即使我这样编译程序:go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH
我仍然获得模块文件的完整路径,在该文件中出现了恐慌,尽管程序的非模块文件未显示完整路径:
goroutine 1 [running]:
monitors/fibre_monitor/logging.FileHandler(0x5e6755,0x1a,0x441,0x0,0x6fc23ac00,0x1,0x500000,0xc000000002,0xb)
/home/gtristan/go/src/monitors/fibre_monitor/logging/file_handler.go:182 +0x11f
main.python_logger(0x5e1383,0x5,0x5e6755,0x101)
src/monitors/fibre_monitor/fibre_monitor.go:73 +0x1b5
main.main_check(0x0,0xc00008e058)
src/monitors/fibre_monitor/fibre_monitor.go:343 +0x65
main.main()
src/monitors/fibre_monitor/fibre_monitor.go:428 +0x56
在跟踪中到处都可以摆脱GOPATH的解决方案是什么?
解决方法
将-trimpath
参数用于go build
(而不是gcflags
或asmflags
):
没有-trimpath
:
$ go build .
$ ./panic
panic: bleh
goroutine 1 [running]:
main.example(0xc000046738,0x2,0x4,0x473f2b,0x5,0xa)
/home/me/stuff/src/github.com/me/testing/panic/main.go:9 +0x39
main.main()
/home/me/stuff/src/github.com/me/testing/panic/main.go:4 +0x72
使用-trimpath
:
$ go build -trimpath .
$ ./panic
panic: bleh
goroutine 1 [running]:
main.example(0xc000046738,0xa)
github.com/me/testing/panic/main.go:9 +0x39
main.main()
github.com/me/testing/panic/main.go:4 +0x72
每go help build
:
-trimpath
remove all file system paths from the resulting executable.
Instead of absolute file system paths,the recorded file names
will begin with either "go" (for the standard library),or a module path@version (when using modules),or a plain import path (when using GOPATH).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。