在Mac上,”go get”命令卡住了。

huangapple go评论94阅读模式
英文:

go get command stuck on Mac

问题

我正在尝试在Golang中安装一些库。但是当我运行go get [package]时,它总是卡住。错误各不相同。其中一个错误如下所示:

➜  alif git:(master) ✗ go get "github.com/go-playground/validator/v10"
go: downloading github.com/go-playground/validator/v10 v10.11.2
go: downloading github.com/go-playground/validator v9.31.0+incompatible
go: github.com/go-playground/validator/v10@v10.11.2: read "https:/proxy.golang.org/@v/v10.11.2.zip": read tcp 192.164.0.2:58505->34.101.4.81:443: read: connection reset by peer

有时会出现连接被拒绝或超时的情况。

➜  alif git:(master) ✗ go get "github.com/go-playground/validator/v10"
go: downloading github.com/go-playground/validator/v10 v10.11.2
go: downloading github.com/go-playground/validator v9.31.0+incompatible
go: golang.org/x/crypto@v0.5.0: verifying go.mod: golang.org/x/crypto@v0.5.0/go.mod: Get "https://sum.golang.org/lookup/golang.org/x/crypto@v0.5.0": net/http: TLS handshake timeout

我的互联网连接正常。实际上,就在2天前,我下载Go依赖项时没有任何问题。

我的Go版本是go1.19,我尝试升级到go1.20,但问题仍然存在。我正在使用macOS M1。我该怎么办?

英文:

I'm trying to install some libraries in golang. But it always stuck when I run go get [package]. The error varies. One of them is like this:

➜  alif git:(master) ✗ go get "github.com/go-playground/validator/v10"
go: downloading github.com/go-playground/validator/v10 v10.11.2
go: downloading github.com/go-playground/validator v9.31.0+incompatible
go: github.com/go-playground/validator/v10@v10.11.2: read "https:/proxy.golang.org/@v/v10.11.2.zip": read tcp 192.164.0.2:58505->34.101.4.81:443: read: connection reset by peer

Sometimes it is a connection refused or timeout.

➜  alif git:(master) ✗ go get "github.com/go-playground/validator/v10"
go: downloading github.com/go-playground/validator/v10 v10.11.2
go: downloading github.com/go-playground/validator v9.31.0+incompatible
go: golang.org/x/crypto@v0.5.0: verifying go.mod: golang.org/x/crypto@v0.5.0/go.mod: Get "https://sum.golang.org/lookup/golang.org/x/crypto@v0.5.0": net/http: TLS handshake timeout

My internet work just fine. And in fact previously like 2 days ago, I have no problem downloading go dependencies.

My go version is go1.19, I tried to upgrade it to go1.20 but the problem still occurs. And I'm using macOS M1. What can I do?

答案1

得分: 0

根据@Para的评论,我需要使用go_proxy。

export GOPROXY=https://proxy.golang.org

但首先,请确保您能否在浏览器中打开golang.org/proxy.golang.org

通过以下命令检查您的GOPROXY是否已设置:

go env
英文:

Based on @Para's comment. I need to use go_proxy.

export GOPROXY=https://proxy.golang.org

But first, make sure you can open golang.org/proxy.golang.org in your browser or not.

Make sure your GOPROXY is set by checking the go env with this command

go env

huangapple
  • 本文由 发表于 2023年2月8日 08:36:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380356.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定