Go get the download package to solve the problem failed

Due to some force majeure, domestic use go getwill often issue a timeout occurs when the installation package command. This article describes some common solutions.

Clone from github

golang image library established on a github, as https://github.com/golang/netit is corresponding to https://golang.org/x/netthe image library. To download golang.org/x/netthe package, the package can create directories on the local use of git clonethe source code files to pull respective packets, 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 can be downloaded from some golang.org mirror sites.

Installation gopm

go get -u github.com/gpmgo/gopm

Use gopm install third-party packages

Without -gparameters, dependencies will download .vendordirectory; with -gparameters, can be dependent package to GOPATHthe directory.

gopm get -g golang.org/x/net  

Use goproxy

Go version 1.11 can be set later GOPROXYthis variable to set the proxy. If you have a proxy server you can put the environment variable to your agent. First of all open go modulesupport:

Performed in the Mac / linux:

export GO111MODULE=on

Windows platform to perform:

SET GO111MODULE=on

2019.6.10 update: goproxy.cn

We here at https://goproxy.cnan example:

In Mac / linux you can execute the following command to set:

export GOPROXY=https://goproxy.cn

Windows platform in cmdexecuting the following command set:

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

Or in PowerShellexecution:

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

Guess you like

Origin www.cnblogs.com/nickchen121/p/11517465.html