Table of Contents
Problem description
Solution
Manual download
Set proxy
Home Backend Development Golang Quickly solve the problem of unsuccessful go get golang.org/x package

Quickly solve the problem of unsuccessful go get golang.org/x package

Dec 02, 2021 pm 02:42 PM
get golang google

This article is provided by the go language tutorial column to introduce how to solve the go get golang.org/x package failure problem with one click. I hope it will be helpful to friends in need!

One-click solution to go get golang.org/x package failure

Problem description

When we use go get, When executing commands such as go install, go mod, etc., the corresponding packages or dependent packages will be automatically downloaded. However, due to well-known reasons, packages similar to golang.org/x/... will fail to download. As shown below:

$ go get -u golang.org/x/sys

go get golang.org/x/sys: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
Copy after login

Solution

So how do we solve the problem? After all, we still need to create bugs~

Manual download

Our common golang.org/x/... packages are generally available on GitHub. Mirror warehouse correspondence. For example, golang.org/x/text corresponds to github.com/golang/text. Therefore, we can manually download or clone the corresponding GitHub repository to the specified directory.

mkdir $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone git@github.com:golang/text.git
rm -rf text/.git
Copy after login

When you need to specify the version, this method has no solution, because most of the mirror warehouses on GitHub do not have tags. Moreover, how can programmers do it manually, especially because there are too many dependencies.

Set proxy

If you have a proxy, you can set the corresponding environment variable:

export http_proxy=http://proxyAddress:port
export https_proxy=http://proxyAddress:port
Copy after login

Or, use all_proxy## directly #:

export all_proxy=http://proxyAddress:port
Copy after login
go mod replace

Starting from Go 1.11 version, new support for

go modules is used to solve package dependency management issues. This tool provides replace, which is to solve the problem of package aliases and also solve the problem that golang.org/x cannot be downloaded.

go module is integrated into the native go mod command, but if your code base is in $GOPATH, The module function is not enabled by default. It is very simple to enable it. You can enable it through an environment variable export GO111MODULE=on.

The following is a reference example:

module example.com/hello

require (
    golang.org/x/text v0.3.0
)

replace (
    golang.org/x/text => github.com/golang/text v0.3.0
)
Copy after login
Similarly, there are third-party package management tools such as glide and gopm, which provide us with different solutions.

GOPROXY environment variable

Finally comes the ultimate killer of this article -

GOPROXY.

We know that starting from the

Go 1.11 version, the go module package dependency management tool is officially supported.

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 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, we certainly recommend using the

GOPROXY solution to this environment variable, provided that Is Go version >= 1.11.

Finally, Qiniu has also launched a domestic proxy goproxy.cn to facilitate domestic users to access inaccessible packages faster, which is really conscience.

The above is the detailed content of Quickly solve the problem of unsuccessful go get golang.org/x package. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Google Pixel 9 Pro XL gets tested with desktop mode Google Pixel 9 Pro XL gets tested with desktop mode Aug 29, 2024 pm 01:09 PM

Google has introduced DisplayPort Alternate Mode with the Pixel 8 series, and it's present on the newly launched Pixel 9 lineup. While it's mainly there to let you mirror the smartphone display with a connected screen, you can also use it for desktop

Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Aug 24, 2024 am 06:43 AM

Google recently responded to the performance concerns about the Tensor G4 of the Pixel 9 line. The company said that the SoC wasn't designed to beat benchmarks. Instead, the team focused on making it perform well in the areas where Google wants the c

Google opens AI Test Kitchen & Imagen 3 to most users Google opens AI Test Kitchen & Imagen 3 to most users Sep 12, 2024 pm 12:17 PM

Google's AI Test Kitchen, which includes a suite of AI design tools for users to play with, has now opened up to users in well over 100 countries worldwide. This move marks the first time that many around the world will be able to use Imagen 3, Googl

Pixel 9 Pro XL vs iPhone 15 Pro Max camera comparison reveals surprising Google wins in video and zoom performance Pixel 9 Pro XL vs iPhone 15 Pro Max camera comparison reveals surprising Google wins in video and zoom performance Aug 24, 2024 pm 12:32 PM

The Google Pixel 9 Pro and Pro XL are Google's answers to the likes of the Samsung Galaxy S24 Ultra and the Apple iPhone 15 Pro and Pro Max. Daniel Sin on YouTube(watch below) has compared the Google Pixel 9 Pro XL to the iPhone 15 Pro Max with some

Google Pixel 9 Pro XL ranks 2nd in DxOMark\'s \'Global\' smartphone camera ranking Google Pixel 9 Pro XL ranks 2nd in DxOMark\'s \'Global\' smartphone camera ranking Aug 23, 2024 am 06:42 AM

Google's new Pixel 9 series has introduced a new variant that wasn't present in previous lineups, the Pixel 9 Pro XL. It is essentially identical to the non-XL variant (pre-order at Amazon), but as the name suggests, it has a larger screen. The two e

Google confirms Pixel 9 Pro Fold incompatibility with official wireless charging accessories thanks to curious design Google confirms Pixel 9 Pro Fold incompatibility with official wireless charging accessories thanks to curious design Sep 01, 2024 am 06:31 AM

The Pixel 9 Pro Fold is akin to a volte-face for Google's nascent foldable division. In fact, such are the differences between thePixel 9 Pro Foldand the Pixel Fold that the former has been compared more against the OnePlus Open (curr. $1,399.99 on A

First Google Pixel 9a footage shows full redesign with much earlier release also rumoured First Google Pixel 9a footage shows full redesign with much earlier release also rumoured Aug 27, 2024 am 06:35 AM

Hardly any time has passed since Google announced its first Pixel 9 series smartphones. In fact, it has only just started shipping the Pixel 9, Pixel 9 Pro and Pixel 9 Pro XL (curr. $1,099 on Amazon). By contrast, Pixel 9 Pro Fold pre-orders will not

Google responds to lackluster benchmark scores of Tensor G4 inside the Pixel 9 line Google responds to lackluster benchmark scores of Tensor G4 inside the Pixel 9 line Aug 20, 2024 pm 09:49 PM

From the get-go, the Google Pixel series was never about beating the top-performing competitors in performance benchmarks. The case for the Google Pixel 9 lineup isn't much different, as the early benchmark results show that the Tensor G4 is quite be

See all articles