「Go」解决go编译出现timeout的问题

背景

Go 编译时无法连接其网站,有如以下报错:

Windows的报错

1
2
go: downloading github.com/xiecat/xhttp v0.0.0-20220117022559-2545617efd91
main.go:8:2: github.com/kataras/golog@v0.1.7: Get "https://proxy.golang.org/github.com/kataras/golog/@v/v0.1.7.zip": dial tcp 172.217.163.49: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

Linux的报错

1
main.go:8:2: github.com/kataras/golog@v0.1.7: Get "https://proxy.golang.org/github.com/kataras/golog/@v/v0.1.7.zip": dial tcp 172.217.160.113:443: i/o timeout

解决办法

Windows 10

设置国内代理地址

1
2
set GOPROXY=https://goproxy.cn
set GO111MODULE=on

Linux & ubuntu

设置代理

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

先执行上面的命令,然后再重新执行编译命令就行了。

参考

https://www.sssins.com/2022/08/14/37991.html