Go Modules 无法识别 GOPATH 下的文件
Go Modules does not recognize files under GOPATH
我试图在 intellij 中设置 GO 模块,并试图在 GOPATH 下导入一个包。当我使用 Go Modules 时,它似乎没有 'import' 来自 GOPATH 的包。关于我可能做错了什么的任何想法?
下面是截图。左图:GoModules,无法识别包。右图:简单的GO项目,识别包。
我试过做同步包,但没有成功。
Go 版本 - 1.12.3
。
两种支持的模式(“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).
如果您希望使用磁盘上的软件包,请参阅
我遇到了这个问题,我为每个项目使用了这个设置,它解决了我的问题。
但我仍在寻找全局 GO 模块配置。
我试图在 intellij 中设置 GO 模块,并试图在 GOPATH 下导入一个包。当我使用 Go Modules 时,它似乎没有 'import' 来自 GOPATH 的包。关于我可能做错了什么的任何想法?
下面是截图。左图:GoModules,无法识别包。右图:简单的GO项目,识别包。
我试过做同步包,但没有成功。
Go 版本 - 1.12.3
两种支持的模式(“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).
如果您希望使用磁盘上的软件包,请参阅
我遇到了这个问题,我为每个项目使用了这个设置,它解决了我的问题。
但我仍在寻找全局 GO 模块配置。