[英]Using -mod flag in go CLI
I was reading through godoc on how I can keep my dependencies up to date: https://golang.org/ref/mod#build-commands我正在阅读 godoc,了解如何使我的依赖项保持最新: https://golang.org/ref/mod#build-commands
It says that -mod=mod
flag can be used to automatically update the go.mod file.它说
-mod=mod
标志可用于自动更新 go.mod 文件。 But I am not able to use it.但我无法使用它。
This is the command that I tried:这是我尝试过的命令:
% go get -mod=mod ./..
flag provided but not defined: -mod
usage: go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]
Run 'go help get' for details.
I am obviously missing something because I can't seem to get the flag to work.我显然错过了一些东西,因为我似乎无法让旗帜工作。
After some experiments, it looks that only quite old versions of Go understand go get -mod=
, in particular version 1.11.经过一些实验,看起来只有相当旧的 Go 版本才能理解
go get -mod=
,尤其是 1.11 版本。 So the documentation is outdated and you could report it.所以文档已经过时了,你可以报告它。
Officially recommended on Go version 1.14 or newer: to automatically update an existing go.mod
file and to download dependencies, instead of doing go get -mod=mod.
官方推荐在 Go 版本 1.14 或更高版本上:自动更新现有的
go.mod
文件并下载依赖项,而不是执行go get -mod=mod.
, simply run: ,只需运行:
go get -d .
For the sake of the example being complete, you could now actually build everything and put binaries into $GOBIN
(or $GOPATH/bin
) with:为了使示例完整,您现在可以实际构建所有内容并将二进制文件放入
$GOBIN
(或$GOPATH/bin
)中:
go install
If it still doesn't work, a couple of things to check:如果它仍然不起作用,请检查几件事:
go
to the latest versiongo
更新到最新版本The online documentation that you are reading is always about the latest official version, while you might be using an older version.您正在阅读的在线文档始终是最新的官方版本,而您可能使用的是旧版本。 Check your version:
检查您的版本:
go version
With the current pace of Go development, most people are trying to update as soon as they can.以目前Go的开发速度,大部分人都在争取尽快更新。 Follow https://golang.org/doc/install
关注https://golang.org/doc/install
Apparently, there is no easy way to read older documentation online.显然,没有简单的方法可以在线阅读旧文档。 Instead, I use
godoc
tool to do it locally:相反,我使用
godoc
工具在本地执行此操作:
go get -v golang.org/x/tools/cmd/godoc
godoc -http=127.0.0.1:6060
Leave the above command running , then in your browser go to http://127.0.0.1:6060/cmd/go/保持上述命令运行,然后在浏览器中 go 到http://127.0.0.1:6060/cmd/go/
This way I've checked for example what the old docs said about -mod
flag.通过这种方式,我检查了例如旧文档所说的关于
-mod
标志的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.