Gogland 是 JetBrains 公司推出的 Go 語言集成開發環境。Gogland 一樣基於 IntelliJ 平臺開發,支持 JetBrains 的插件體系。官方:https://www.jetbrains.com/go/。關於 Goland 相關配置參考該連接便可。Goland 用的好好的,爲啥忽然想用到 VSCode 呢 ?VSCode 是目前比較流行的 IDE 工具,在功能方面也相對齊全,使用方面也比較友好。不過對於 Golang 來講,配置起來不算太麻煩,只能說其中有一些比較坑的地方,今天咱們也就是來填坑的(該死的天朝網絡,要否則也不用這麼費勁了)。html
1、Golang 環境配置git
關於 Goland 的系統環境配置,這裏就不在過多講解,能夠直接參考該連接的前半部分便可。github
2、安裝配置 VSCodegolang
下載連接:https://code.visualstudio.com/網絡
選擇本身系統對應的版本就能夠,這個作 IT 的都不知道那就轉行吧。tcp
2.1 安裝 golang 插件工具
進入Visual Studio Code,使用快捷鍵F1,打開命令面板測試
在上圖光標處·輸入 exten ,而後選擇「Extensions:Install Extension」,以下圖fetch
查詢並安裝 Go 插件ui
提示:在插件列表中,選擇 Go,進行安裝,安裝以後,系統會提示重啓Visual Studio Code。因爲我這裏已經安裝過了,因此不會出現 "Install" 選項。
2.2 開啓自動保存功能
打開Visual Studio Code,找到菜單File -> Preferences -> Settings,以下圖:
選中 "User Settings" 配置以下內容
{ "files.autoSave": "onFocusChange", "editor.fontSize": 18, "go.goroot": "D:\\Go", "go.gopath": "D:\\Golang\\MyGO" }
其餘保持默認配置便可;
2.3 執行相關命令(自行安裝好git)
更多詳細信息參考:https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go
1)安裝gocode
打開命令提示符(以管理員身份打開),輸入:
go get -u -v github.com/nsf/gocode
2)安裝godef
go get -u -v github.com/rogpeppe/godef
3)安裝golint
# 建立 $GOPATH/src/golang.org/x cd $GOPATH/src/golang.org/x git clone https://github.com/golang/tools.git git clone https://github.com/golang/lint.git # 完成以上步驟後,執行 go get golang.org/x/lint/golint
若是你遇到了相似以下錯誤,就能夠經過 git clone 的方式把包下載到本地,再進行安裝便可解決問題;
Fetching https://golang.org/x/tools/go/buildutil?go-get=1 https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. package golang.org/x/tools/go/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
4)安裝go-find-references
go get -u -v github.com/lukehoban/go-find-references
5)安裝go-outline
go get -u -v github.com/lukehoban/go-outline
6)安裝goreturns
go get -u -v sourcegraph.com/sqs/goreturns
7)安裝gorename
go get -u -v golang.org/x/tools/cmd/gorename
提示:若是還提示報錯,由於前面已經git clone 下來了,能夠執行執行"go install golang.org/x/tools/cmd/gorename";
8)安裝gopkgs
go get -u -v github.com/tpng/gopkgs
9)安裝go-symbols
go get -u -v github.com/newhook/go-symbols
2.4 寫一個程序進行測試
能夠看到可以進行相關提示。這裏咱們執行完整程序測試一下,程序是否正常。
OK,徹底沒有問題了。