我遇到了一个问题,即-trimPATH没有从stacktrack的最后一行中删除GOPATH. 以下是堆栈跟踪的快照:

Apr 15 09:56:59 10-79-108-22 system-health[3923528]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x144efd2]
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: goroutine 1 [running]:
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: github.com/go-redis/redis.(*cmdable).HGetAll(0xc002cc78b0, 0x0, 0x0, 0x0)
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: github.com/go-redis/redis.(*cmdable).HGetAll(0xc002cc78b0, 0x0, 0x0, 0x0)
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         github.com/go-redis/redis@v6.13.2+incompatible/commands.go:923 +0xd2
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: controller/systemhealth.someOtherFunc(...)
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         controller/systemhealth/system_health.go:676
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: controller/systemhealth.someFunction(...)
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         controller/systemhealth/system_health.go:680
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: controller/systemhealth.ServiceInitialize()
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         controller/systemhealth/system_health.go:685 +0x6b
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: main.main()
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         /home/hemant/dev/go/src/controller/go-controller.go:743 +0x231e

我的GOPATH = /home/hemant/dev/go/src

构建时我的编译器标志是:-gcflags=-trimpath=$GOPATH -trimpath -asmflags=-trimpath=$GOPATH -trimpath

GOPATH也应该从最后一行中删除.

另一个附带问题:是否可以不公开目录路径而仅具有文件名?

推荐答案

根据 comments ,仅设置-trimpath而不设置-gcflags=...-asmflags=....解决了这个问题(这可能是由于与GOPATH混淆).

Go相关问答推荐

有没有更简单的方法在Go中编写这个逻辑?

语法-for循环中的initit陈述是否允许分配?

理解Golang中的IOTA和常量

如何使用 Go 连接到非默认 firestore 数据库?

格式化 Azure SDK 的 golang 时间

我可以扫描表中每个项目的最高范围键值吗?

如何将字节文件高效地读入int64切片?

如何在 Go 中将 int 转换为包含 complex128 的泛型类型?

Wire google Inject with multi return from provider 函数

查找、解析和验证邮箱地址

Go 并发、goroutine 同步和关闭通道

go 是否对 struct 使用空间填充之类的东西?

使用反射在 struct 内迭代切片 struct

如何在gin中获取参数值数组

Unescape 在 rss 中两次逃脱了标题

GORM GIN 更新查询导致 500 内部服务器错误

不能使用 *T 类型的变量作为参数类型

有没有一种方法可以确保传递的值具有使用泛型的某些字段?

在 Go 泛型中,如何对联合约束中的类型使用通用方法?

更改单个像素的 colored颜色 - Golang 图像