go - 无法确定源目录的模块路径

标签 go go-modules

我在 root/src/abc 中有 go.mod 文件。在 root/build-scripts 中,我有一个执行 go get 的脚本。因为我使用的是 Go 1.11,所以我没有使用 go 路径,而是 root/src/abc 中的 mod 文件负责其他导入,但构建脚本中使用的包会出错:

go: cannot determine module path for source directory.

有什么建议吗?

最佳答案

如果没有看到您运行的实际命令,很难确定地说什么,因为您的脚本似乎不会更改工作目录,因此它们执行的 go 命令不在模块的根目录中文件夹或其任何子文件夹。

引自Command Go: The go.mod file:

A module version is defined by a tree of source files, with a go.mod file in its root. When the go command is run, it looks in the current directory and then successive parent directories to find the go.mod marking the root of the main (current) module.

因此您的脚本应该将工作目录更改为 root/src/abc 或其任何子文件夹,否则 go 命令将找不到 go.mod 文件。

关于go - 无法确定源目录的模块路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52978070/

相关文章:

go - 如何使用 bigtable Go 客户端支持分页?

docker - 如何将 go mod 与本地包和 docker 一起使用?

amazon-web-services - 如何将带有模块的 Go 应用程序部署到 AWS EB

go - 保护特定的 Pat 路线

go - 不改变接收器的接口(interface)

ruby - 如何使用 Go 共享库在 Ruby 中传递字符串数组并获取字符串数组?

go - 在 Go 中实现 io.Writer 接口(interface)

go - 我该如何修复 go get : disabled by -mod=vendor

git - 控制 Go 包版本

go - 从 go.mod 手动获取依赖项?