Go模块无法识别GOPATH下的文件 [英] Go Modules does not recognize files under GOPATH

查看:1014
本文介绍了Go模块无法识别GOPATH下的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was trying to set up GO Modules in intellij and was trying import a package under GOPATH. When I use Go Modules, it doesnt seem to 'import' the packages from GOPATH. Any ideas on what I could be doing wrong?

以下是屏幕截图.左图:GoModules,无法识别该软件包.右图:简单的GO项目,可以识别软件包.

Below is a screenshot. Left pic: GoModules, which doesnt recognize the package. Right Pic: Simple GO project, which recognized the packages.

我尝试做同步包,没有运气.

I tried doing sync package, with no luck.

Go版本-1.12.3

Go version - 1.12.3

.

推荐答案

两个受支持的模式("GOPATH模式"和模块感知模式")是互斥的模式.这意味着您不能同时拥有模块和GOPATH.

The two supported modes ("GOPATH mode" and "module-aware mode") are mutually exclusive modes. This means you can't have both, you can't mix modules and GOPATH.

引用到命令:GOPATH和模块:

使用模块时,GOPATH不再用于解析导入.但是,它仍用于存储下载的源代码(在GOPATH/pkg/mod中)和编译的命令(在GOPATH/bin中) ).

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).

还有命令go:初步模块支持:

要获得更细粒度的控制,Go 1.11中的模块支持应考虑一个临时环境变量GO111MODULE,可以将其设置为三个字符串值之一:off,on或auto(默认值).如果GO111MODULE = off,那么go命令将永远不使用新的模块支持.相反,它在供应商目录和GOPATH中查找依赖关系.我们现在将其称为"GOPATH模式".如果GO111MODULE = on,则go命令需要使用模块,从不咨询GOPATH.我们将其称为命令可识别模块或在模块可识别模式"下运行.如果GO111MODULE = auto或未设置,则go命令根据当前目录启用或禁用模块支持.仅当当前目录位于GOPATH/src之外且其本身包含go.mod文件或位于包含go.mod文件的目录之下时,模块支持才启用.

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.

在模块感知模式下,GOPATH不再定义构建期间导入的含义,但仍会存储下载的依赖项(在GOPATH/pkg/mod中)和已安装的命令(在GOPATH/bin中) ,除非设置了GOBIN).

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模块无法识别GOPATH下的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆