go - 在 go 中删除跟踪中的模块路径

标签 go module trace gopath

我需要删除跟踪中的绝对路径,它对应于导入的模块。即使我这样编译我的程序:go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH尽管程序的非模块文件没有显示完整路径,但我仍然获得了模块文件的完整路径,其中出现了 panic :

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, 0x1a, 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 的参数(不是 gcflagsasmflags ):
没有 -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, 0x2, 0x4, 0x473f2b, 0x5, 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).

关于go - 在 go 中删除跟踪中的模块路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63831540/

相关文章:

python : 'import module' vs 'import module as'

R 跟踪在函数内部无法正常工作?

network-programming - 谷歌去 : binding multicast socket

go - 检查 channel 长度在 `for{ len(c) }` 中变得无响应

go - 如何打破 scanner.scan() for 循环?

javascript - 如何在 NodeJS 上使用 nanoid 模块?

python - settings.py 中的命名空间问题

java - BTrace 的开销是多少

ASP.NET 和 System.Diagnostics 跟踪 - 我是否遗漏了什么,或者这是一个坏主意?

json - 如何将 JSON 数组转换为对象