英文:
Goland doesnt recognize module
问题
我在使用Goland时遇到了无法识别导入的问题。
所以,像这样的基本示例结构
- main.go
- go.mod
- folder/something.go
来自folder
的导入无法被识别。
例如,在main.go
中的下面导入是无效的,Goland会显示Cannot resolve directory somename
的错误信息:
import "somename/folder"
go.mod是使用go mod init somename
进行初始化的。
为什么会发生这种情况?为什么Goland无法将somename
解析为我创建的模块?
英文:
I'm having issues with Goland recognizing my imports.
So, with a basic sample structure like this
- main.go
- go.mod
- folder/something.go
imports from folder
arent recognized.
E.g. below import, within main.go
isn't valid, and Goland complains with the message Cannot resolve directory somename
import "somename/folder"
The go.mod was initialized with go mod init somename
Why is this happening? Why Goland can't resolve somename to the module that I created?
答案1
得分: 11
在GoLand的文档中提到,如果你没有从IDE本身创建Go项目,那么你需要手动配置它来使用Go模块。
如果你在IDE中创建了一个新的Go模块项目,Go模块已经被启用。如果你从Github上拉取了你的Go模块项目,你需要手动启用Go模块。
所以,我猜这就是你面临的问题所在。但是你可以按照文档的说明正确配置你的IDE。
英文:
Refer: JetBrains GoLand Docs: Working with Go modules
In GoLand's docs, it is mentioned that if you haven't created the Go project from the IDE itself then you have to configure it to use Go modules manually.
> If you create a new Go modules project in the IDE, Go modules are already enabled. If you pulled your Go modules project from Github, you need to enable Go modules manually.
So, I assume that's why you are facing the problem. But you can follow the docs and configure your IDE correctly.
答案2
得分: 2
如果IDE无法识别您的内部包,则:
- 在设置中找到
Go Modules
。 - 启用
启用Go模块集成
复选框。
英文:
If the IDE is unable to recognize your internal packages then:
- Inside Settings find
Go Modules
- Enable the
Enable Go modules integration
checkbox.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论