簡體   English   中英

在 go 中刪除跟蹤中的模塊路徑

[英]removing module path in trace in 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, 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).

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM