Build golang+vscode development environment under WIN10 (with pictures and texts, fool-like tutorial)

Installation sequence

Install Git >> Install Go >> Install vscode >> Install go plugin >> Install third-party dependencies

One, prepare tools

git installation package, go installation package, vscode installation package
Insert picture description here

Official download address

Git:https://gitforwindows.org/

Go:https://golang.google.cn/dl/
Insert picture description here

vsocde:https://code.visualstudio.com/

2. Installation environment

  1. Install the git environment, run the Git-2.20.1-64-bit.exe file to install, if you do not need to modify the installation path, the default is next until the installation is complete
    (the git installation is not detailed here)

  2. Install the go environment, run the go1.11.4.windows-amd64.msi file to install, the same as above, the default is next until the installation is complete [ Go can not be installed on the C drive ]
    Insert picture description here

Pay attention to the configuration of go environment variables : GOBIN and GOROOT (GOPATH will be described in detail later, do not configure it yet)
Insert picture description here
Add to Path
Insert picture description here

Three, configure the GOPATH working directory

Now create a custom GOPATH directory, for example: E:\GOPROJECTS, and create three folders src, pkg, and bin in this directory.
Insert picture description here
Open My Computer-(right click) Properties-Advanced System Settings-Environment Variables, add a new user Environment variable GOPATH
Insert picture description here

Open the console (win+r, enter cmd, press Enter), enter go env to view the go configuration information.
Insert picture description here
Note: Check the go configuration information here, and you may find that there is no change. This is because the change takes time.
It is recommended to wait a while after the configuration and then use the console to view

I configured it at the beginning, but I couldn’t see the path I configured. It kept showing the path of the default C drive. I was wondering about it after a while, and it became the path I configured.

Fourth, install vscode

Run the VSCodeUserSetup-x64-1.30.2.exe file to install, select I accept the agreement, if you do not need to modify the installation path, the default next step until the installation is complete After the
Insert picture description here
installation is complete, open vscode, extension (Extension)-enter go search-click install to install the plug-in
Insert picture description here
Open the configuration file settings.json to
Insert picture description here
modify settings.json, enter the following

{
    
    
 
    "go.buildOnSave": "workspace",
    "go.lintOnSave": "package",
    "go.vetOnSave": "package",
    "go.buildTags": "",
    "go.buildFlags": [],
    "go.lintFlags": [],
    "go.vetFlags": [],
    "go.coverOnSave": false,
    "go.useCodeSnippetsOnFunctionSuggest": false,
    "go.formatOnSave": true,
    "go.formatTool": "goreturns",
    "go.goroot": "D:/tool/go",
    "go.gopath": "E:/gowork",
    "go.gocodeAutoBuild": false,
    "files.autoSave":"onFocusChange",
    "launch": {
    
    
      "version": "0.2.0",
      "configurations": [
        {
    
    
          "name": "GoLaunch",
          "type": "go",
          "request": "launch",
          "mode": "debug",
          "remotePath": "",
          "port": 2345,
          "host": "127.0.0.1",
          "program": "${fileDirname}",
          "env": {
    
    
            "GOPATH":"E:/gowork"
          },
          "args": [],
          "showLog": true
        }
      ]
    }
  }  

Note: The "go.formatOnSave" item will be marked with a green line. The reason is unknown, but no impact has been found so far, so it can be ignored

Five, install third-party dependency packages

Open vscode and create a new hello.go file with the following content:

package main
 
import "fmt"
 
func main(){
    
    
 
  fmt.Println("hello,go")
 
}

When you save the file, a pop-up box will appear in the lower right corner of vscode, prompting you to install dependencies. If your computer can overturn the wall, you can directly click install all to install it.

Can't get over the wall

Here, many online tutorials are git clone, and then install, but if the speed of git clone is still very slow, it will be a headache.

Here, share a blogger’s solution:

Six, configure the Go global module agent

The steps are as follows:
First, the Windows user opens Powershell, a blue interface, note that it is not cmd! If you don't know, open the search under the window directly, and then enter powershell, and you can search it out.
Then enter the commands one by one:
$env:GO111MODULE="on"

$env:GOPROXY=“https://goproxy.io”

go env -w GOPROXY=https://goproxy.io,direct

go env -w GOPRIVATE=*.corp.example.com

Insert picture description here

Then, we reopen the VsCode interface, the following will prompt to install the plug-in, we choose Install ALL, it will be installed successfully

Finally, step
Insert picture description here
into the world of go!


reference

How to solve the installation failure of golang plugin in vscode: https://blog.csdn.net/qq_40876767/article/details/105658433
Build a golang+vscode development environment:
https://www.cnblogs.com/ecake/p/10398436.html

Guess you like

Origin blog.csdn.net/qq_43229056/article/details/109501538