解决go编译出现timeout的问题

某次编译go工具发现无法连接其网站,诸如以下报错:

Windows的报错
go: downloading github.com/xiecat/xhttp v0.0.0-20220117022559-2545617efd91
main.go:8:2: github.com/kataras/[email protected]: 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的报错
main.go:8:2: github.com/kataras/[email protected]: 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(win10亲测):

设置国内代理地址

set GOPROXY=https://goproxy.cn

set GO111MODULE=on

参考连接

Linux(ubuntu亲测):

设置代理

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

先执行上面的命令,然后再执行编译命令就行了。
参考链接

你可能感兴趣的:(解决go编译出现timeout的问题)