Cover
Before starting
- This article is divided into two parts
- Installing Golang
- Configuring the Vscode Golang development environment
- Golang version 1.10.3
- Linux/macos The default installation path is
/usr/local/go
Download & Install
- Download the corresponding version of Golang
- If it is MacOS can run
brew install go
to install
Environmental variable
The environment variable setting for this article is for Linux/macos, which is configured as follows:
$ vim ~/.profile#在文件末尾加入export GOROOT=/usr/local/goexport PATH=$PATH:GOROOT/bin
Goroot environment variable represents our go installation path, we can automatically find our go installation path when we use the IDE, to achieve the purpose of automatic configuration of the Go SDK.
/usr/local/go/bin This path is added to the environment variable path, we can directly enter the common commands such as go when using terminal.
After source ~/.profile
the configuration is done to update the environment variables, enter go version
Verify whether the configuration is successful
$ go versiongo version go1.10.3 darwin/amd64
Hello world!
Write your Hello world! Program
Inputvim hello.go
pakage mainimport "fmt"func main() { fmt.println("Hello World!")}
Input go run hello.go
to execute code, output:
Hello World!
Set up Vscode Go Extension
Open Vscode Search for go in the plugin bar
Go Extension
Since the wall is installed directly after the installation, you will be prompted that there are several plug-in installation failures
Failed
Workaround
Switch to%gopath%/using a terminal
Create a new missing folder according to the following directory structure
src├── github.com| └── golang└── golang.org └── x
We $ git clone git@github.com:golang/tools.git
manually download the tools package by command, or download the extract directly, then put the Tools entire folder %GOPATH%/src/golang/x
under the path, then we put the Lint folder under the Tools folder into the %GOPATH%/src/golang/x
%GOPATH%/src/github.com/
following directory structure:
src├── github.com| ├── golang| | └── lint| ...└── golang.org └── x ├── tools └── lint
Finally execute the go install github.com/golang/lint/golint
command so that the lint installation succeeds (no return error)
Then we can continue to manually enter the command to install the failed plugin:
$ go install github.com/ramya-rao-a/go-outline$ go install github.com/acroca/go-symbols$ go install golang.org/x/tools/cmd/guru$ go install golang.org/x/tools/cmd/gorename...
Reopen Vscode If you are prompted to install the plugin, let it be installed automatically, and the result may return the following failure message:
Error message returned by terminal
For this scenario we continue to create the folder manually as above to download and install, taking the Gocode plugin as an example:
- Download the zip archive and unzip it to https://github.com/mdempsky/gocode according to the information
- Put the extracted files in
%GOPATH%/src/github.com/mdempsky/gocode
- Perform
go install github.com/mdempsky/gocode