在Deepin Linux上用Visual Studio Code配置GoLang開發環境

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

背景

  在上一篇在Deepin Linux上用Sublime Text3配置GoLang開發環境 文章中介紹了用Sublime Text 3進行Golang開發,本篇中再介紹最新的Golang開發神器Visual Studio Code。

Visual Studio Code重新定義和最佳化了代碼編輯,以便產生和調試新式 Web 應用程式和雲應用程式。 您可以在常用平台(Linux、OS X 和 Windows)上免費使用 Visual Studio Code。

Go語言安裝

詳情查看:安裝Golang

VSCode安裝

  從 Visual Studio Code官網下載最新版本1.4.0並安裝。

外掛程式安裝

  在左側導航條有5個按鈕,依次是資源管理員,搜尋,GIT,調試,擴充,點擊擴充按鈕,然後在市集中搜尋擴充Go進行外掛程式安裝。


vs-go


  外掛程式安裝後重啟Visual Studio Code,再次點擊已安裝的外掛程式可以看到外掛程式的介紹。


Go for Visual Studio Code

Visual Studio Code Go外掛程式配置選項

  從菜單中選擇"檔案" -> “喜好設定" -> "使用者佈建",進行如下設定


settings
// 將設定放入此檔案中以覆蓋預設設定{    "files.autoSave": "onFocusChange",    "go.buildOnSave": true,    "go.lintOnSave": true,    "go.vetOnSave": true,    "go.buildFlags": [],    "go.lintFlags": [],    "go.vetFlags": [],    "go.useCodeSnippetsOnFunctionSuggest": false,    "go.formatOnSave": false,    "go.formatTool": "goreturns",    "go.gopath":"/home/tonny/golang",    "go.goroot": "/usr/local/go"}

Go工具安裝

  由於國內對golang.org訪問不通暢,採用變通的方法來安裝Go工具。

➜ tonny@tonny-pc  ~ mkdir -p $GOPATH/src/golang.org/x ➜ tonny@tonny-pc  ~ cd $GOPATH/src/golang.org/x➜ tonny@tonny-pc  ~ git clone https://github.com/golang/tools.git➜ tonny@tonny-pc  ~ go get golang.org/x/tools/cmd/godoc➜ tonny@tonny-pc  ~ ll $GOROOT/bin

  其他相關工具安裝,參考如下:

➜ tonny@tonny-pc  ~  vi gotools.sh#!/bin/bash # Get all go tools for vscodego get -u -v github.com/nsf/gocodego get -u -v github.com/rogpeppe/godefgo get -u -v github.com/golang/lint/golintgo get -u -v github.com/lukehoban/go-find-referencesgo get -u -v github.com/lukehoban/go-outlinego get -u -v sourcegraph.com/sqs/goreturnsgo get -u -v golang.org/x/tools/cmd/gorenamego get -u -v github.com/tpng/gopkgsgo get -u -v github.com/newhook/go-symbols➜ tonny@tonny-pc  ~  chmod +x gotools.sh ➜ tonny@tonny-pc  ~  ./gotools.sh

調試工具dlv

go get github.com/derekparker/delve/cmd/dlv$ make install

Note: If you are using Go 1.5 you must set GO15VENDOREXPERIMENT=1 before continuing. The GO15VENDOREXPERIMENT env var simply opts into the Go 1.5 Vendor Experiment.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.