Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to quickly solve the problem of unsuccessful go get golang.org/x package

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to quickly solve the problem of unsuccessful go get golang.org/x package". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to quickly solve the problem of unsuccessful go get golang.org/x package".

Problem description

When we use commands such as go get, go install, go mod, and so on, we automatically download the corresponding package or dependent package. But for well-known reasons, similar to golang.org/x/... The package will fail to download. As follows:

$go get-u golang.org/x/sysgo 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.371) solution

So how do we solve the problem? After all, we still have to make bug.

Download manually

Our common golang.org/x/... Package. Generally speaking, there is an official image repository on GitHub. 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/xcd $GOPATH/src/golang.org/xgit clone git@github.com:golang/text.gitrm-rf text/.git

This method has no solution when you need to specify a version, because most of the image repositories on GitHub do not have tag. And, manual, how can programmers do it, especially the dependency, too much.

Set up proxy

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

Export http_proxy= http://proxyAddress:portexport https_proxy= http://proxyAddress:port

Or, just use all_proxy:

Export all_proxy= http://proxyAddress:portgo mod replace

Starting from Go version 1.11, new support has been added for go modules to solve package dependency management problems. This tool provides replace, which not only solves the alias problem of the package, but also solves the problem that golang.org/x cannot download.

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, and it is very easy to turn on export GO111MODULE=on through an environment variable.

The following is a reference example:

Module example.com/hellorequire (golang.org/x/text v0.3.0) replace (golang.org/x/text = > github.com/golang/text v0.3.0)

Similarly, there are third-party package management tools such as glide and gopm, which provide us with solutions in different ways.

GOPROXY environment variable

Finally, it comes to the ultimate killer of this article-GOPROXY.

We know that the go module package dependency management tool has been officially supported since Go version 1.11.

In fact, the GOPROXY environment variable has been added. If this variable is set, the source code will be downloaded through the proxy address set by this environment variable instead of being downloaded directly from the code base. This is undoubtedly the greatest boon for us and other developers who are unable to access the Internet scientifically.

Even more gratifying is that the open source project goproxy.io has helped us achieve what we want. The project allows developers to build their own GOPROXY proxy services with one click. At the same time, a common proxy service https://goproxy.io is also provided. We only need to set this environment variable to download the walled source package normally:

Export GOPROXY= https://goproxy.io

However, you need to rely on go module functionality. You can open MODULE through export GO111MODULE=on.

If the project is not in GOPATH, you cannot use go get..., but you can use go mod... Related orders.

You can also turn it off by leaving the environment variable empty, export GOPROXY=.

For Windows users, you can set it in PowerShell:

$env:GOPROXY = "https://goproxy.io"

Finally, we certainly recommend using GOPROXY as an environment variable, provided that Go version > = 1.11.

Thank you for your reading, the above is the content of "how to quickly solve the problem of unsuccessful go get golang.org/x package". After the study of this article, I believe you have a deeper understanding of how to quickly solve the problem of unsuccessful go get golang.org/x package. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report