【问题标题】:go: cannot find main module; see 'go help modules'go: 找不到主模块;见“去帮助模块”
【发布时间】:2022-04-26 19:25:31
【问题描述】:

我最近开始使用 Go。我在 vscode 上安装了 go 的扩展,我可以使用一些命令,例如 go rungo 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


【解决方案1】:

您必须先初始化项目,然后才能运行测试:

go mod init puppy

https://golang.org/cmd/go#hdr-Module_maintenance

【讨论】:

  • 我受苦了!!谢谢!
猜你喜欢
  • 2020-10-25
  • 2016-09-08
  • 2017-07-29
  • 1970-01-01
  • 1970-01-01
  • 2018-02-21
  • 2022-12-15
  • 1970-01-01
  • 2019-03-19
相关资源
最近更新 更多