Golang+vscode Installation and Configuration

Source: Internet
Author: User
Tags install go sourcegraph
This is a creation in Article, where the information may have evolved or changed. First, install the Golang
Golang in setting the Windows environment variables, there is a problem, like in the folder after adding \, set up after the best to change again.
Edit environment variable Goroot, change C:\Go\ to C:\Go
Edit environment variable path, delete it; C:\Go\bin\, and then write the%goroot%\go at the very beginning;
Verify that you install
C:\>go Versiongo version go1.7 windows/amd64

Second, installation Vscode
VS's extension plug-in c:\users\[user name]\.vscode\extensions directory, want to install the offline copy of their own, and then restart two times Vscode
Ctrl+p Enter ext install go, and then enter, may be a considerable part of the user network is not very good, or an offline way to install it
After the installation is complete, it is recommended to change the settings to AutoSave, file-to-preferences, user settings, and Setting.json input on the right
Put the settings in this file to override the default settings {    //control the automatic saving of updated files. Accepted values: "Off", "Afterdelay", "Onfocuschange". If set to "Afterdelay", you can configure the delay in "Files.autosavedelay".    "Files.autosave": "On"}



Three, installation tools
Install git before performing this step and set the environment variable Gopath,gopath is your working directory, which directory you want to write code in.
The following tools will also be installed in this directory
Once configured, execute the following commands in the CMD environment (if you install git and configure Gopath, you will get an error if you execute the following command)
#安装gocodego Get-u-v github.com/nsf/gocode# install Godefgo get-u-v github.com/rogpeppe/godef# install Golintgo get-u-V github.com/ golang/lint/golint# Install Go-find-referencesgo get-u-v github.com/lukehoban/go-find-references# install Go-outlinego get-u-V github.com/lukehoban/go-outline# Install Goreturnsgo get-u-v sourcegraph.com/sqs/goreturns# install Gorenamego get-u-V golang.org/x/tools/cmd/gorename# installing Gopkgsgo get-u-V github.com/tpng/gopkgs

The above command is from a blog, the following is the official Microsoft document script
Go 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-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-symbolsgo get-u-v golang.org/x/tools/cmd/g Uru

In fact, in order to use F5 debugging, we also need DLV tools
Go get-v-u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv

Detailed installation information and extensions can be done, see Microsoft's official documentation
Https://marketplace.visualstudio.com/items?itemName=lukehoban.Go

The debug run-time mode parameter can be set to:

Debug compiles the program folder under the debugger and launches the contents. [The default]remotetest debug tests in the Programs folder.] exec to run the pre-built binaries of the program folder that builds the current code instead.

Test Code Test.go

Test code test.gopackage Mainimport "FMT" Func Main () {    fmt. Println ("Hello,world")}

Under the Vscode, F5 can see the results.



The following command line runs and compiles the binary commands
#运行go文件的命令go run test.go# compiled into EXE run go build test.go# above generate Test.exe, below is run Test.exetest.exe

In fact, the debug generated under the Vscode is compiled binary files, plus the suffix name of the. exe can be run like a command line exe


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.