使用jetbrains设置golang环境 [英] Setup golang environment using jetbrains

查看:471
本文介绍了使用jetbrains设置golang环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用idea(13.1社区版)设置了golang开发envionemnt。
看起来SDK已被识别。
但是,我无法通过右键单击源文件夹下的新建来创建GO文件。 (go项是灰色的)
目前我必须手动将文件扩展名设置为.go并编辑文件,但自动完成是可以的。
这只存在于我的Mac上(版本10.9.4)
我已经将GOPATH目录访问模式设置为777,但仍然不起作用。
这在Windows7上正常工作。
那么我该怎么做?



这就是它在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
设置的envionment设置
这个是几个步骤!



如果在GOPATH中只有一个目录,并且在使用作为项目一部分的软件包时在该路径内创建项目,则仍然必须指定整个导入路径对他们来说,不是相对的。例如:

$ ul
$ g $ g $ g $ g $ g $ g $ / $ c $是/ 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







  • 你有最新版本的插件,如问题756 说明IntelliJ IDEA 13不会在Mac OS X上创建项目目录结构。






    最后,检查IDEA是否正确检测到 GOROOT GOPATH

    请参阅页面< a href =https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md#--mac-os-x =nof ollow noreferrer>修复缺少的环境路径(Mac)。






    OP python 增加

  • 如果我创建了一个新的Java命令行应用程序,那么我可以右键单击并添加新的Go文件



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

    解决方案

    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.

    这篇关于使用jetbrains设置golang环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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