


Solution to the failure of downloading go get golang.org/x package in China
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!
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
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"
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
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Reading and writing files safely in Go is crucial. Guidelines include: Checking file permissions Closing files using defer Validating file paths Using context timeouts Following these guidelines ensures the security of your data and the robustness of your application.

How to configure connection pooling for Go database connections? Use the DB type in the database/sql package to create a database connection; set MaxOpenConns to control the maximum number of concurrent connections; set MaxIdleConns to set the maximum number of idle connections; set ConnMaxLifetime to control the maximum life cycle of the connection.

The Go framework stands out due to its high performance and concurrency advantages, but it also has some disadvantages, such as being relatively new, having a small developer ecosystem, and lacking some features. Additionally, rapid changes and learning curves can vary from framework to framework. The Gin framework is a popular choice for building RESTful APIs due to its efficient routing, built-in JSON support, and powerful error handling.

How to use Gomega for assertions in Golang unit testing In Golang unit testing, Gomega is a popular and powerful assertion library that provides rich assertion methods so that developers can easily verify test results. Install Gomegagoget-ugithub.com/onsi/gomega Using Gomega for assertions Here are some common examples of using Gomega for assertions: 1. Equality assertion import "github.com/onsi/gomega" funcTest_MyFunction(t*testing.T){

Best practices: Create custom errors using well-defined error types (errors package) Provide more details Log errors appropriately Propagate errors correctly and avoid hiding or suppressing Wrap errors as needed to add context

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

The difference between the GoLang framework and the Go framework is reflected in the internal architecture and external features. The GoLang framework is based on the Go standard library and extends its functionality, while the Go framework consists of independent libraries to achieve specific purposes. The GoLang framework is more flexible and the Go framework is easier to use. The GoLang framework has a slight advantage in performance, and the Go framework is more scalable. Case: gin-gonic (Go framework) is used to build REST API, while Echo (GoLang framework) is used to build web applications.

How to address common security issues in the Go framework With the widespread adoption of the Go framework in web development, ensuring its security is crucial. The following is a practical guide to solving common security problems, with sample code: 1. SQL Injection Use prepared statements or parameterized queries to prevent SQL injection attacks. For example: constquery="SELECT*FROMusersWHEREusername=?"stmt,err:=db.Prepare(query)iferr!=nil{//Handleerror}err=stmt.QueryR
