Configure goproxy for golang development environment in vscode

Posted by awared on Thu, 13 Jan 2022 22:31:34 +0100

Like npm, pip and other package management tools, your packages are pulled locally from the Internet. However, due to the domestic network, you have to change the domestic agent for these tools, otherwise the download is very slow or fails directly.

As mentioned in this article, you also need to pull some things from the Internet to develop and download plug-ins (development packages) for golang. Unfortunately, it always fails!!!

At this time, we should think of the problem of agency!!! (in this article, by default, your go language development environment is installed, but the package cannot be downloaded)

Execute go env, and the output information is as follows:

We focus on these two variables:

GO111MODULE				// Set go module
GOPROXY					// Set up proxy server

to configure

It can be set in the environment variable, which is equivalent to setting the agent globally; You can also set it in the vscode editor

Configuration in environment variables

Windows creates GO111MODULE and GOPROXY user variables in computer - > System - > advanced system settings - > user environment respectively, and their values are shown in the following figure:

//Turn on GO MODULE function
GO111MODULE=on
//Set up GO proxy
GOPROXY=https://mirrors.aliyun.com/goproxy/   

Among them, the agent can also be replaced by another one

GO111MODULE=on
GOPROXY=https://goproxy.cn,direct

Or use the following command in cmd to set:

# Enable Go Modules function
$env:GO111MODULE="on"
# Configure GOPROXY environment variables
$env:GOPROXY="https://goproxy.io"

# Set private warehouses without proxy, and separate multiple with commas (optional)
$env:GOPRIVATE=*.corp.example.com

For details, please refer to: go set proxy and GOPROXY.IO - a global agent for the Go module

After configuration, first turn off cmd, windows + R calls out the terminal, enter cmd, and check whether the environment variable configuration of go is set successfully through the go env command.  

From the picture, we can see that it is indeed a success!!!

Configuration in vscode

The vscode editor is set in the path of file - > Preferences - > Settings - > User - > Application - > proxy server, as shown in the following figure:

For the installation and configuration of other packages, refer to the vscode environment configuration of golang https://www.cnblogs.com/marshhu/p/11848020.html

golang basic dependency package

Running the golang program requires some basic dependent packages. However, due to the slow downloading of the domestic network, you can find the corresponding packages on github or through this link
https://github.com/marshhu/golang-package Download it, unzip it, put it under the GOP a t h / S R C command, and install it through the following command. After successful installation, install it under the GOPATH/src command and through the following command. After successful installation, install it in the GOPATH/src directory and through the following command. After successful installation, you will see it in the GOPATH/bin directory exe.

golang Run basic dependency package download $GOPATH/src Directory, run the following command:

go install github.com/mdempsky/gocode

go install github.com/uudashr/gopkgs/cmd/gopkgs

go install github.com/ramya-rao-a/go-outline

go install github.com/acroca/go-symbols

go install github.com/fatih/gomodifytags

go install github.com/josharian/impl

go install github.com/davidrjenni/reftools/cmd/fillstruct

go install github.com/haya14busa/goplay/cmd/goplay

go install github.com/godoctor/godoctor

go install github.com/go-delve/delve/cmd/dlv

go install github.com/stamblerre/gocode

go install github.com/rogpeppe/godef

go install github.com/sqs/goreturns

go install golang.org/x/tools/cmd/guru

go install golang.org/x/tools/cmd/gorename

go install golang.org/x/lint/golint

reference resources

golang alicloud goproxy usage: https://studygolang.com/articles/21963?fr=sidebar
Go Modules and goproxy cn:
https://juejin.im/post/5d8ee2db6fb9a04e0b0d9c8b
VS code golang development environment setup:
https://www.cnblogs.com/sevenyuan/p/6522429.html
Go language vscode environment configuration: https://blog.csdn.net/wf19930209/article/details/82112590
Vs code to build a golang development environment (how to set up an agent): https://blog.csdn.net/easy_mind/article/details/78214696
vscode environment configuration of golang: https://www.cnblogs.com/marshhu/p/11848020.html

Topics: Go Visual Studio Code