英文:
Setup golang environment using jetbrains
问题
我已经使用Idea(13.1社区版)设置了一个使用golang的开发环境。
看起来SDK已经被识别了。
然而,我无法通过右键单击源文件夹下的“新建”选项来创建一个GO文件(“go”选项是灰色的)。
目前,我必须手动将文件扩展名设置为“.go”并编辑文件,但自动完成是可以的。
这个问题只存在于我的Mac上(版本为10.9.4)。
我已经将GOPATH目录的访问模式设置为777,但仍然无法工作。
在Windows 7上运行良好。
那么我应该怎么办?
这是在Windows上的样子:
谢谢VonC,我已经尝试过/Users/Tom/go
的设置,但没有起作用,所以我切换到了这个根路径。
这是我的先前设置:
macbook:home root# go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mac/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
而在/Users/Tom/Go
目录下是这样的:
谢谢VonC,然而这个方法并不起作用。我不确定原因是什么。
这是使用GOCODE的环境设置:
这是几个步骤!
步骤1
顺便提一下,我注意到在创建新的Go项目时,Mac和Windows之间存在一些差异。
在这一步,Windows平台会显示一个“项目SDK”,而Mac则不会。
英文:
I have setup an golang developing envionemnt using idea (13.1 community edition).
It seems the SDK is recognized.
However, I could not create a GO file by right click the "New" under the source folder. (The item of "go" is grayed)
Currently I have to manually set the file extension to ".go" and edit the file, but autocomplete is OK.
This only exist on my Mac(with version 10.9.4)
I have set the GOPATH directory access mode to 777 but still not work.
This works fine on windows7.
So what should I do ?
This is what it looks like in windows
Thanks VonC, I already tried the /Users/Tom/go setting, this doesn't work and I switch to this root path.
here's my previous setting
macbook:home root# go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mac/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
And this is what is look like in the /Users/Tom/Go
Thanks VonC, however, this doesn't work. I am not sure what's the reason.
This is the envionment setting using GOCODE
This is several steps!
step1
By the way, I noticed that there are a difference from mac and windows when creating a new Go Project
at this step, the windows platform will show a "project sdk" while mac won't.
答案1
得分: 2
确保你的IntelliJ项目引用了GOPATH
中的正确路径。
从插件页面上可以看到:
如果你的GOPATH中只有一个目录,并且你在该路径下创建了一个项目,当你使用项目中的包时,你仍然必须指定它们的完整导入路径,而不是相对路径。例如:
GOPATH
是:/home/florin/go
正确设置名为demogo的项目的方式是:/home/florin/go/src/github.com/dlsniper/demogo/
- 新包的路径是:/home/florin/go/src/github.com/dlsniper/demogo/newpack
- 正确的导入语句是:github.com/dlsniper/demogo/newpack,而不是newpack
此外,请确保你安装了最新版本的插件,因为issue 756说明了IntelliJ IDEA 13在Mac OS X上无法创建项目目录结构。
最后,请检查IDEA是否正确检测到了GOROOT
和GOPATH
:
参考页面"修复缺失的环境路径(Mac)"。
- 如果我创建一个新的Go项目,这个新功能是禁用的。
-
如果我创建一个新的Java命令行应用程序,然后我可以右键单击并添加新的Go文件。
英文:
Make sure your IntelliJ project reference the right path within GOPATH
.
From the plugin page:
> If you have only one directory in the GOPATH and you are creating a project inside that path when you are working with packages that are part of the project you must still specify the whole import path for them, not the relative one. Example:
> - GOPATH
is: /home/florin/go
the correct way to setup a project called demogo is: /home/florin/go/src/github.com/dlsniper/demogo/
- new package is: /home/florin/go/src/github.com/dlsniper/demogo/newpack
- the correct import statement is: github.com/dlsniper/demogo/newpack not newpack
Also make sure you have the latest version of the plugin, as issue 756 illustrates that IntelliJ IDEA 13 doesn't create the project directory structure on Mac OS X.
Finally, check if IDEA has correctly detected GOROOT
and GOPATH
:
See the page "Fix missing environment paths (Mac)".
The OP python adds in the comments:
> - If I have create a new Go project, this new feature is disabled.
-
If I create a new Java Command line App, then I could right click and add new Go file.
答案2
得分: 1
在顶级项目或src目录上右键单击,然后选择标记目录为 > 源代码根目录。完成后,您将能够访问启用的Go上下文菜单。
英文:
Right-click on either the top-level project or on the src directory and then go to Mark Directory As > Sources Root. After this you will be able to access the enabled Go context menus.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论