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
Official download address
Git:https://gitforwindows.org/
Go:https://golang.google.cn/dl/
vsocde:https://code.visualstudio.com/
2. Installation environment
-
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) -
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 ]
Pay attention to the configuration of go environment variables : GOBIN and GOROOT (GOPATH will be described in detail later, do not configure it yet)
Add to Path
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.
Open My Computer-(right click) Properties-Advanced System Settings-Environment Variables, add a new user Environment variable GOPATH
Open the console (win+r, enter cmd, press Enter), enter go env to view the go configuration information.
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
installation is complete, open vscode, extension (Extension)-enter go search-click install to install the plug-in
Open the configuration file settings.json to
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
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
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