gpt4 book ai didi

Go Modules 无法识别 GOPATH 下的文件

转载 作者:数据小太阳 更新时间:2023-10-29 03:38:51 24 4
gpt4 key购买 nike

我试图在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com