Due to some force majeure, timeout problems often occur when installing packages using the Go Get command in China. This article introduces several common solutions.

Out of cloning

Golang on dead simple to set up a image libraries, such as https://github.com/golang/net is corresponding to the https://golang.org/x/net image libraries. To download the golang.org/x/net package, you can use Git clone to pull the source code of the package after creating the package directory locally.

mkdir -p $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/net.git

Using gopm

GoPM can be downloaded from some of Golang.org’s mirror sites.

Install gopm

go get -u github.com/gpmgo/gopm

Install third party packages using GOPM

Do not add -g parameter, will rely on the package download. Vendor directory below; Add the -g parameter to download the dependent packages to the GOPATH directory.

gopm get -g golang.org/x/net  

Using goproxy

In version 1.11 of Go, you can set the GOPROXY variable to set the proxy. If you have your own proxy server, you can set this environment variable to be your own proxy. First enable Go Module support:

On Mac/ Linux:

export GO111MODULE=on

Execution on Windows platform:

SET GO111MODULE=on

2019.6.10 update: goproxy. Cn

Let’s take https://goproxy.cn as an example:

On Mac/ Linux, you can set it by executing the following commands:

export GOPROXY=https://goproxy.cn

Windows platform execute the following command in CMD to set:

SET GOPROXY="https://goproxy.cn"

Or execute it in PowerShell:

C:\> $env:GOPROXY = "https://goproxy.cn"