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

藏色散人
Release: 2021-10-15 15:28:14
forward
3510 people have browsed it

##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
Copy after login
Use gopm

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

Install gopm

go get -u github.com/gpmgo/gopm
Copy after login

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
Copy after login
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
Copy after login
Execute on Windows platform:

SET GO111MODULE=on
Copy after login
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
Copy after login
For Windows platform, execute the following command in

cmd to set:

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

PowerShell:

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

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template