[英]Where does go put imports when using modules with no GOPATH set?
I'm toying around with converting a project at work to be a module. 我想将工作中的项目转换为模块。 My understanding is it should make deploys much easier since $GOPATH won't have to be set up properly.
我的理解是,由于不必正确设置$ GOPATH,它应该使部署更加容易。
In my existing project I ran go mod init <project path>
, and checked in go.mod
and go.sum
. 在我现有的项目中,我运行
go mod init <project path>
,并签入了go.mod
和go.sum
。 As a test, I opened a new terminal, unset GOPATH
, cloned my project into /tmp, go build
, and everything worked great but it left me with questions. 作为测试,我打开了一个新终端,未
unset GOPATH
,将项目克隆到/ tmp, go build
,一切正常,但仍然给我带来了疑问。 I expected my imports to be downloaded into a vendor folder but nothing. 我希望导入文件可以下载到供应商文件夹中,但什么也不会下载。
Where does go modules put the packages it has to go get
when no $GOPATH is set? 当未设置$ GOPATH时,go模块将
go get
的软件包放在哪里?
From the modules help : 从模块帮助 :
When using modules, GOPATH is no longer used for resolving imports.
使用模块时,GOPATH不再用于解析导入。 However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin).
但是,它仍用于存储下载的源代码(在GOPATH / pkg / mod中)和已编译的命令(在GOPATH / bin中)。
So in your case if GOPATH is unset it will use the default GOPATH ( $HOME/go/
) and thereby store the cached imports in: $HOME/go/pkg/mod
因此,在您的情况下,如果未设置GOPATH,它将使用默认的GOPATH(
$HOME/go/
),从而将缓存的导入存储在: $HOME/go/pkg/mod
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.