An overview of the

Recently, I found Visual Studio Code very useful. This paper introduces a basic development environment of Go language based on Visual Studio Code on Windows.

Basic Software Installation

Install Visual Studio Code:

This is nothing to say, go to the official website to download and install.

Install Git for Windows.

The Go Get tool uses Git to get remote code packages. Therefore, you need to install Git, download and install it from the official website.

Step 3. Install the go plug-in of vscode: click the extension button in vscode to search for go and install the go plug-in.

Basic Environment Configuration

The configuration of environment variables is not described here, there are many online related tutorials.

Step 1. ConfigurationGOPATHEnvironment variables:

GOPATH is a feature of the GO language, and the code is stored in the SRC directory under GOPATH. It can be configured according to personal needs. I configured D:\code\golang.

Step 2. ConfigurationPATHEnvironment variables:

Because the executable files compiled by go code are stored by default in the bin directory under GOPATH, add %GOPATH%\bin to the PATH environment variable.

Golang.org/x Installation package

In the process of learning go, packages written by third parties are often needed. Among them, the golang.org/x package is developed by the GO team and is the most widely used. However, golang.org/x is on Google’s servers. Google’s server IP is blocked by the powerful GFW and can’t get through without a ladder. That’s where the Go Team came in — they created a github mirror image of these packages. You can see it on Golang’s project homepage on Github. The description of the warehouse containing [mirror] is the mirror of the package related to golang.org/x. Search the keyword mirror to view all mirror packages:

Tools, NET, Lint, image.

Open the Git bash terminal (searchable from the Start menu) and create the appropriate directory:

$ mkdir -p $GOPATH/src/golang.org/x
Copy the code

Run the git clone command to clone the package to the newly created directory:

$ git clone https://github.com/golang/tools.git $GOPATH/src/golang.org/x/tools
$ git clone https://github.com/golang/net.git $GOPATH/src/golang.org/x/net
$ git clone https://github.com/golang/lint.git $GOPATH/src/golang.org/x/lint
$ git clone https://github.com/golang/image.git $GOPATH/src/golang.org/x/image
Copy the code

This allows you to use the relevant utility classes using import golang.org/x/tools.

Install the VScode GO tool

To write go programs smoothly, you need to install the following tools:

gocode
gopkgs
go-outline
go-symbols
guru
gorename
dlv
gocode-gomod
godef
godef-gomod
goreturns
golint
gotests
gomodifytags
impl
fillstruct
goplay
Copy the code

These can be easily installed using vscode. Press F1 or Ctrl+Shift+P in vscode, type Go:Install/Update Tools and press enter. Once the installation is complete, you can write the GO code. Without the previous steps to install the Golang/X package, errors like golang.org/x/tools would have been reported.

At this point, vscode can:

  1. Smart tips.
  2. Automatically import the corresponding package when saving.
  3. Error checking.
  4. Automatically formats files when saved.
  5. And so on and so on.

Enjoy!

About me: Personal homepage Simple book nuggets