go語言的集成開發環境仍不成熟,試用了liteide,感覺很不適應,彈出菜單對程序員的干擾太大。所以就試大牌的IntelliJ IDEA,這工具本來是JAVA開發陣營的,不過它已經變為一個非常強大的支持多種語言的集成環境了。
1、go環境
下載Go1.5.1(由於國內偉大的牆,golang.org訪問被牆,搞點技術真是不易,從Golang中國的的百度雲盤下載是不錯的選擇,http://pan.baidu.com/s/1hq1mrDM),安裝很方便,直接解壓到c:\go目錄中即可。系統PATH環境變量中加上c:\go\bin。
2、IDEA
安裝JDK1.8.0_60_x64,默認安裝在C:\Program Files\Java目錄下。安裝IDEA時需要。
安裝IntelliJ IDEA Community Edition 14.1.5到默認位置C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.5。
啟動IDEA程序,在設置主題時,選Skip All and Set Defaults。工具裝備就緒。
3、編譯go-lang-idea-plugin插件
(不願折騰這一步的朋友到這里下載我用1.0.0pre-release的build518編譯生成好的jar文件:http://download.csdn.net/detail/slofslb/9182113,沒辦法有時要到CSDN下載點材料卻沒積分)
安裝插件go-lang-idea-plugin,JetBrains官方的插件jar文件比較舊,所以到開源網站上找源代碼自己編譯后安裝,這個插件的源代碼從這個網址下載:https://github.com/go-lang-plugin-org/go-lang-idea-plugin/releases,直接下載的源代碼master.zip中缺少idea的項目文件。我下載的是go-lang-idea-plugin--518.zip,我直接放在D:\go-lang-idea-plugin--518下。
用IDEA打開項目,也就是d:\go-lang-idea-plugin--518目錄
此時會有git版本控制的警告,可以不管它,也可以關閉它。
此時直接編譯,會報SDK不存在,要進行幾項關鍵設置。
1)SDK設置
菜單File->Project Structure...,找到Platform Settings/SDK,點加號,加上JDK,選1.8,注意是JDK,而不是JRE,C:\Program Files\Java\jdk1.8.0_60。
再加上IntelliJ Platform Plugin SDK,就是它的安裝目錄:C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.5,Internal Java Platform綁定1.8。
再設置Project SDK: IntelliJ IDEA Community Edition IC-141.2735.5(java version 1.8.0)
2)Modules設置
此時進Project Settings/Modules的設置,應該 Module SDK使用了project SDK。
3)編譯
再編譯會有些警告,但編譯成功!!!
4)生成jar
Build->Prepare All Plugin Modules For Deployment,成功后會在d:\go-lang-idea-plugin--518目錄中生成了intellij-go.jar,我們需要的就是這一個寶貝。此時這個go-lang-idea-plugin--518項目的源代碼就編譯完成了,如果你不搞JAVA開發,以后就不用它了。
4、安裝插件
進入IDEA的File->Settings->Plugin配置插件,install plugin from disk...,選intellij-go.jar文件,OK后,會提示重啟Intellij IDEA。
5、在IDEA中開發go項目
new project,項目類型選go
比如d:\goproj\hello文件夾下,建立一個hello項目,提示你設置GO SDK,此時發現IDEA可以自動找到go1.5.1目錄了。
在project里新建hello.go,運行時會有兩種方式,一種對應於go build后運行,一種對應於go run。
package main
import "fmt"
func main(){
fmt.Println("hello world")
}
官網上給出新建idea中的go項目的方法:
https://github.com/go-lang-plugin-org/go-lang-idea-plugin/wiki/v1.0.0-Setup-initial-project
IntelliJ IDEA
- create a new project by going to Create New Project | Go and follow the setup steps
Other IDEs
- create a new blank project and you'll be prompted to setup a GO SDK for it
Once you've created the project according to your IDE, please follow the steps below
- after your project has been created, you can then add your GOPATH packages to it so that you can use all the plugin features
- to do, go to File | Settings | Languages & Frameworks | Go Libraries. Here you have a few options to choose from, but the recommended (and most tested one at the moment) is to create a new entry under Global Libraries that points to your GOPATH directory (see the example bellow). (強調要把項目主目錄加到全局庫中,可能這樣就不需要設置GOPATH了?)
- if you've followed the steps correctly, then "everything" should work for you
One concrete example would be (under Linux, paths may vary on other OSes):
- GOROOT (aka sdk home) /usr/local/go
- GOPATH (the path in Go Libraries | Global Libraries) /home/florin/golang/
- project home /home/florin/golang/src/github.com/dlsniper/misc
有人說要設置這些環境變量,但我在1.5.1中並沒有用到,直接用go.exe命令行工具時我用過GOPATH。
新建 變量名:GOBIN 變量值 :C:\Go\bin
新建 變量名:GOOS 變量值:windows
新建 變量名:GOROOT 變量值:C:\Go
新建 變量名:GOPATH 變量值:d:\goproj\hello






