Solution to the failure of downloading go get golang.org/x package in China

藏色散人
Release: 2020-10-14 16:26:24
forward
2876 people have browsed it

The following column golang tutorial will introduce to you the solution to the failure of domestic download go get golang.org/x package. I hope it will be helpful to friends in need!

Solution to the failure of downloading go get golang.org/x package in China

GOPROXY environment variable

We know that starting from Go 1.11 version, Officially supports the go module package dependency management tool.
In fact, the GOPROXY environment variable has also been added. If this variable is set, the source code will be downloaded through the proxy address set by this environment variable, instead of downloading directly from the code library as before. This is undoubtedly the greatest good news for us developing citizens who cannot access the Internet scientifically.
What’s even more gratifying is that the open source project goproxy.io (https://github.com/goproxyio/goproxy) helps us achieve what we want. This project allows developers to build their own GOPROXY proxy service with one click. At the same time, a public proxy service https://goproxy.io is also provided. We only need to set this environment variable to download the blocked source code package normally:

export GOPROXY=https://goproxy.io
Copy after login

However, Needs to depend on go module function. MODULE can be turned on via export GO111MODULE=on.
If the project is not in GOPATH, you cannot use go get..., but you can use go mod... related commands.
It can also be turned off by setting this environment variable blank, export GOPROXY=.

For Windows users, you can set it in PowerShell:

$env:GOPROXY = "https://goproxy.io"
Copy after login

Finally, of course, we recommend using the GOPROXY solution to this environment variable. Prerequisite Is Go version >= 1.11.

Explanation

This article is not original, because of the dependency problem, it bothered me for about three days (at this stage, I only tinker with go at night, and during the day Other work), I found a post on the Internet through Google, which is the content above. After configuring GOPROXY, the relevant dependencies were downloaded successfully. The reason why I post the content here is because the page may not be accessible in China... The original post contains more than one method, but those methods have appeared in domestic posts. I have not found the only solution above, and I have not found it yet. Original address: One-click solution to go get golang.org/x package failure (https://shockerli.net/post/go-get-golang-org-x-solution/)

Thank you In the previous personality (https://shockerli.net/about/)

If the package still cannot be downloaded, execute the following statement on the console:

go env -w GOPROXY=https://goproxy.cn,https://gocenter.io,https://goproxy.io,direct
Copy after login

                                                                                                                       

The above is the detailed content of Solution to the failure of downloading go get golang.org/x package in China. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.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