Home  >  Article  >  Backend Development  >  What should I do if go get fails to download the package? Don't rush!

What should I do if go get fails to download the package? Don't rush!

藏色散人
藏色散人forward
2021-10-15 15:28:143498browse

##go get download package failed issue

Due to some force majeure reasons, timeout problems often occur when using the

go get command to install packages in China. This article introduces several common solutions.

Clone from github

golang has established a mirror library on github, such as

https://github.com/golang/net corresponding to https Mirror library at ://golang.org/x/net. To download the golang.org/x/net package, you can create the package directory locally and use git clone to pull the source code file of the corresponding package. The specific operations are as follows:

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

Use gopm to download from some mirror websites of golang.org.

Install gopm

go get -u github.com/gpmgo/gopm

Use gopm to install third-party packages

Without the

-g parameter, the dependent package will be downloaded.vendorUnder the directory; Add the -g parameter to download the dependent package to the GOPATH directory.

gopm get -g golang.org/x/net
Use goproxy

After 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 your own proxy. First enable go module support:

Execute under Mac/linux:

export GO111MODULE=on
Execute on Windows platform:

SET GO111MODULE=on
2019.6.10 update: goproxy. cn

We take

https://goproxy.cn as an example:

You can execute the following command to set up under Mac/linux:

export GOPROXY=https://goproxy.cn
For Windows platform, execute the following command in

cmd to set:

SET GOPROXY="https://goproxy.cn"
or execute in

PowerShell:

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

The above is the detailed content of What should I do if go get fails to download the package? Don't rush!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete