In Go 1.8+ the GOPATH
environment variable is optional. When not set, GOPATH
defaults to $HOME/go
. Is there a variable or function in some standard library package that will show the final value of GOPATH
(I'm hoping for something like runtime.GOROOT()
even when it is inferred in the case that no GOPATH
environment variable has been set?
解析GOPATH值(Go 1.8+)
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- douti0687 2017-01-19 22:14关注
GOPATH
doesn't technically exist in the runtime, it's only used by the build tools.GOARCH
,GOOS
, andGOROOT
are the only variables recorded at compile time, but they still do not effect the execution of the runtime.You can check for
GOPATH
in the environment, and fallback to$HOME/go
if it's not there. However, this still doesn't guarantee that you're getting theGOPATH
used to build the binary, since the application may not have been build by the same user, or even on the same system.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 winform的chart曲线生成时有凸起
- ¥15 msix packaging tool打包问题
- ¥15 finalshell节点的搭建代码和那个端口代码教程
- ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
- ¥15 Centos / PETSc / PETGEM
- ¥15 centos7.9 IPv6端口telnet和端口监控问题
- ¥120 计算机网络的新校区组网设计
- ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
- ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
- ¥20 海浪数据 南海地区海况数据,波浪数据