简体   繁体   English

使用模块时go项目的工作目录在哪里?

[英]Where is the go project working directory when using modules?

I am trying to download, make some tweaks and build a golang project from GitHub.我正在尝试从 GitHub 下载、进行一些调整并构建一个 golang 项目。 The project's instructions are:该项目的说明是:

go get github.com/<vendor>/<projectName>
cd src/github.com/<vendor>/<projectName>
go build .

That used to work in the past — before enabling Go Modules.在启用 Go Modules 之前,这在过去是可行的。

Now I have GO111MODULE=on (go version go1.15.4 linux/amd64 ).现在我有GO111MODULE=on (go version go1.15.4 linux/amd64 )。 When running the first command, go downloads the project as a module and all its dependencies.运行第一个命令时,go 将项目作为模块及其所有依赖项下载。

But then there is no src/github.com/<vendor>/<projectName> folder anymore.但是之后就没有src/github.com/<vendor>/<projectName>文件夹了。 Moreover, the is no folder named <projectName> anywhere in the system.此外,系统中的任何位置都没有名为<projectName>文件夹。

Instead, there is folder pkg/mod/github.com/<vendor> which contains the project folder with weird symbols in its name (exclamation marks etc.) and version identifiers.取而代之的是文件夹pkg/mod/github.com/<vendor> ,其中包含名称中带有奇怪符号(感叹号等)和版本标识符的项目文件夹。

How do I get the project folder available for making tweaks and builds?如何获取可用于进行调整和构建的项目文件夹?

As pointed by @Volker, good old git clone should be used.正如@Volker 所指出的,应该使用旧的git clone

It turns out that it should be used instead of go get github.com/<vendor>/<projectName> (no idea why the project vendor recommends that):事实证明,应该使用它而不是go get github.com/<vendor>/<projectName> (不知道为什么项目供应商建议这样做):

git clone git://github.com/<vendor>/<projectName>
cd <projectName>
go get ./...
# do tweaks here
go build .

If your goal is tweaks, the easiest way it use to use go mod vendor .如果您的目标是调整,那么使用go mod vendor的最简单方法。 https://golang.org/ref/mod#go-mod-vendor https://golang.org/ref/mod#go-mod-vendor

The go mod vendor command constructs a directory named vendor in the main module's root directory that contains copies of all packages needed to support builds and tests of packages in the main module go mod vendor 命令在主模块的根目录中构造一个名为 vendor 的目录,该目录包含支持主模块中包的构建和测试所需的所有包的副本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM