Golang的go get和install命令在从gocenter.io获取时失败,出现”405 Not allowed”错误。

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

Golang's go get and install commands fail with "405 Not allowd" errors from gocenter.io

问题

我暂时无法提供完整的翻译,因为你的内容包含了代码部分,而我只能返回翻译好的部分。请提供不包含代码的内容,我将尽力为你提供翻译。

英文:

I came back to golang after a while, and tried to troubleshoot an open source library.

When I tried to install its dependencies, and even when my IDE (VSCode) tried to install the current language server, I would get errors like the following:

$ go install -v golang.org/x/tools/gopls@latest
go: golang.org/x/tools/gopls@latest: module golang.org/x/tools/gopls: reading https://gocenter.io/golang.org/x/tools/gopls/@v/list: 405 Not Allowed

In an attempt to troubleshoot this, I created another user on my machine and the dependency installation worked when I used that user account.

What is going on?
Why can I no longer install any package with go?

答案1

得分: 1

go模块系统可以使用代理协议来获取依赖项。被使用的代理由go的GOPROXY环境变量控制。

过去,它的默认值可能包括goceter.io,这是JFrog提供的一项服务,但在某个时候被停止了。

在我的情况下,它被设置在go env GOENV指向的文件中,从文件内容中删除这个域名(和其他域名)后,一切都恢复正常了。

现在,gocenter.io不再存在。

你可以使用你喜欢的编辑器编辑文件,然后运行go install -v golang.org/x/tools/gopls@latest命令来安装依赖项。

英文:

The go module system can use a proxy protocol to fetch dependencies. The proxies that are being used are controlled by go's GOPROXY environment variable.

Its default value in the past likely included goceter.io, which was a service offered by JFrog and was discontinued at some point.

$ go env GOPROXY
gocenter.io,goproxy.io,goproxy.cn,proxy.golang.org,direct
$ cat "$(go env GOENV)"
GOPROXY=gocenter.io,goproxy.io,goproxy.cn,proxy.golang.org,direct

In my case, it was being set in the file pointed by go env GOENV, and removing this domain (and others) from the file contents made everything work again.

$ vim "$(go env GOENV)"
# (edit the file using your favorite editor)
$ cat "$(go env GOENV)"
GOPROXY=proxy.golang.org,direct
$ go env GOPROXY
proxy.golang.org,direct
# now gocenter.io is no longer there
$ go install -v golang.org/x/tools/gopls@latest
go: downloading golang.org/x/tools/gopls v0.9.5
go: downloading golang.org/x/tools v0.2.0
# ...

huangapple
  • 本文由 发表于 2022年10月21日 19:13:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/74152799.html
匿名

发表评论

匿名网友

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

确定