Go Modules 无法识别 GOPATH 下的文件

标签 go intellij-idea go-modules

我试图在 intellij 中设置 GO 模块,并尝试在 GOPATH 下导入一个包。当我使用 Go Modules 时,它似乎没有从 GOPATH“导入”包。关于我可能做错了什么的任何想法?

下面是截图。左图:GoModules,无法识别包。右图:简单的 GO 项目,识别包。

我尝试做同步包,但没有成功。

Go 版本 - 1.12.3

Initellij_GO_MOD .

最佳答案

两种支持的模式(“GOPATH 模式”和“模块感知模式”)是互斥的模式。这意味着你不能同时拥有,你不能混合模块和 GOPATH。

引自Command go: GOPATH and Modules:

When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin).

还有Command go: Preliminary module support:

For more fine-grained control, the module support in Go 1.11 respects a temporary environment variable, GO111MODULE, which can be set to one of three string values: off, on, or auto (the default). If GO111MODULE=off, then the go command never uses the new module support. Instead it looks in vendor directories and GOPATH to find dependencies; we now refer to this as "GOPATH mode." If GO111MODULE=on, then the go command requires the use of modules, never consulting GOPATH. We refer to this as the command being module-aware or running in "module-aware mode". If GO111MODULE=auto or is unset, then the go command enables or disables module support based on the current directory. Module support is enabled only when the current directory is outside GOPATH/src and itself contains a go.mod file or is below a directory containing a go.mod file.

In module-aware mode, GOPATH no longer defines the meaning of imports during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod) and installed commands (in GOPATH/bin, unless GOBIN is set).

如果您希望使用磁盘上的软件包,请参阅 How to use a module that is outside of "GOPATH" in another module?

关于Go Modules 无法识别 GOPATH 下的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55650450/

相关文章:

go - 无法通过 SSH 安装 go 模块(私有(private)嵌套存储库)

go - 模块声明为 X 但要求为 Y

file - 如何获取文件的当前位置

mysql - 如何告诉gorm保存丢失的时间。时间字段为NULL而不是 '0000-00-00'?

go - 接口(interface)和指针接收器

templates - 防止模板中转义正斜杠

java - IntelliJ IDEA 与 NetBeans 的性能影响?

java - IntelliJ IDE(社区版)不支持 var 声明 Java 10

go - 拥有 vendor 文件夹有什么好处?

java - Intellij IDEA 复制包 + Spring 应用程序配置的类名