【发布时间】:2022-04-26 19:25:31
【问题描述】:
我最近开始使用 Go。我在 vscode 上安装了 go 的扩展,我可以使用一些命令,例如 go run 和 go build,但是当我运行 go test 时,我收到以下错误:
go: 找不到主模块;请参阅“转到帮助模块”
虽然我有一个*_test.go 文件。
当我运行 go help modules 时,我得到以下输出:
Modules are how Go manages dependencies.
A module is a collection of packages that are released, versioned, and
distributed together. Modules may be downloaded directly from version control
repositories or from module proxy servers.
For a series of tutorials on modules, see
https://golang.org/doc/tutorial/create-module.
For a detailed reference on modules, see https://golang.org/ref/mod.
By default, the go command may download modules from https://proxy.golang.org.
It may authenticate modules using the checksum database at
https://sum.golang.org. Both services are operated by the Go team at Google.
The privacy policies for these services are available at
https://proxy.golang.org/privacy and https://sum.golang.org/privacy,
respectively.
The go command's download behavior may be configured using GOPROXY, GOSUMDB,
GOPRIVATE, and other environment variables. See 'go help environment'
and https://golang.org/ref/mod#private-module-privacy for more information.
【问题讨论】:
-
供进一步参考;
go mod init是第一步的一部分,在您显示的第一个链接中,并在第二个链接中详细介绍。
标签: go go-modules