解决golang编译提示dial tcp 172.217.160.113:443: connectex: A connection attempt failed

时间:2025-02-09 17:32:21

废话不多说,直接开讲
还多新手朋友在编译go的过程中是不是经常会遇到这样的报错
module : Get "/": dial tcp 172.217.160.113:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
你可以试着访问一下,怎么样,访问不了吧,没错,这是被我们伟大的长城防火墙给屏蔽了,你需要改成我们国内可用的代理地址

直接在命令行执行

go env -w GOPROXY=https://goproxy.cn

由于国内的网络环境,我们可以通过配置GOPROXY避免DNS污染导致的模块拉取缓慢或失败的问题,加速你的构建

windows
打开你的终端并执行:

Go GOROOT 与 GOPATH 介绍
GOROOT:  GO 语言的安装路径。
GOPATH:若干工作区目录的路径 自己定义的工作空间。
GOBIN:GO 程序生成的可执行文件(executable file)的路径。
go env -w GOPROXY=,direct

macOS 或 Linux
打开你的终端并执行:

$ export GOPROXY=https://goproxy.cn

或者

$ echo "export GOPROXY=" >> ~/.profile && source ~/.profile

完成。

查看修改效果

go env

环境变量设置

go env -w xxx=xxx

go env -w GO111MODULE=on

然后再次尝试执行你的go命令试试看,搞定了吧