When the Go program is written step by step, it will involve the use of the Go dependency package provided by a third party, such as github.com/spf13/cobra. When the Go GET command is used in China, timeout and other problems often occur, which is really a headache. As we all know, in the domestic network environment, to solve this problem, only to master xx Internet to be completely solved. But xx Internet access is the need to spend extra costs, so what to do?

This article will introduce a Go proxy goProxy way to solve the above problems, so that you do not spend money, and can quickly download and install.

1. Introduction to goproxy.cn

After version 1.11 of Go, you can set the environment variable GOPROXY to set up the proxy to speed up downloads. At present, goproxy.cn is the most widely used in China, which is known as the most reliable Go module agent in China.

It has the following characteristics:

  • Fast download: We are using qiuniuyun CDN to accelerate our service worldwide, and we have not set any bandwidth limits. With thousands of CDN nodes and a single node bandwidth of 40Gbps+, you will be given the ability to download module versions very quickly.

  • No limits: Not only do we not set bandwidth limits. Furthermore, we haven’t set any rate limits yet. This means you can use our services in any scenario, such as CI/CD. You can even use our service as an upstream proxy like goproxy.baidu.com.

  • Full featured: We’ve been using the latest version of Go, even an unstable one. Because we provide cutting edge functionality. In particular, we support the agent’s default checksum database, sum.golang.org. You don’t have to do anything extra for it to work.

  • Data visualization: To give you a better understanding of the activity of all modules in our service, we have introduced the first statistics API in the Go module agent world. With a decent RESTful API design, you will be able to easily query statistics for all module versions in our service.

2. Configure goproxy.cn

It is recommended to use Go 1.13 or later.

Open your terminal and execute the following command:

$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct
Copy the code

MacOS or Linux:

$ export GO111MODULE=on
$ export GOPROXY=https://goproxy.cn
Copy the code

or

$ echo "export GO111MODULE=on" >> ~/.profile
$ echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
$ source ~/.profile
Copy the code

Windows:

Open the CMD command line and run:

C:\> $env:GO111MODULE = "on"
C:\> $env:GOPROXY = "https://goproxy.cn"
Copy the code

or

1. Open Start and search env 2. Select Edit System Environment Variables 3. Click "Environment Variables..." Button 4. Under "< your Username > User Variables" section (top half) 5. Click "New..." Button 6. Select the "Variable Name" input box and enter "GO111MODULE" 7. Select the "variable Value" input box and enter "ON" 8. Click the "OK" button 9. Click "New..." Button 10. Select the Variable Name input box and enter GOPROXY 11. Select the Variable Value input box and enter https://goproxy.cn. 12. Click the ok buttonCopy the code

3, summary

With the above goProxy setup, go Get command downloads will be quick, easily solving the timeout problem. In addition, goproxy. IO can also be used to accelerate, and the configuration method is exactly the same as goproxy.cn.

Reference article:

  1. goproxy.cn/
  2. www.goproxy.io/zh/