如何为go get命令指定DNS?

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

How to specify dns for go get command

问题

我有一个依赖项,它发布在公司的GitLab上,只能通过特定DNS服务器的域名进行发现。在我的本地环境中,go get命令无法获取这样的依赖项,错误信息如下:

go get our-domain.com/group/library@v0.1.0
go: our-domain.com/group/library@v0.1.0: verifying go.mod: our-domain.com/group/library@v0.1.0/go.mod: reading https://sum.golang.org/lookup/our-domain.com/group/library@v0.1.0: 410 Gone
        server response: not found: our-domain.com/group/library@v0.1.0: unrecognized import path "our-domain.com/group/library": https fetch: Get "https://our-domain.com/group/library?go-get=1": dial tcp: lookup our-domain.com on 8.8.8.8:53: no such host

如果我在Docker中构建,将DNS添加到/etc/docker/daemon.json中,它可以正常工作:

{ "dns": ["1.2.3.4"] }

如何在本地获取依赖项?
我在MacOS上运行,使用go1.13版本。

我尝试将DNS地址添加到网络设置中,但go get仍然不使用它。

英文:

I have a dependency which is published in company's GitLab and is only discoverable with domain name from a certain dns server. The go get command is failing to fetch such dependency on my local environment like this:

go get our-domain.com/group/library@v0.1.0                                            
go: our-domain.com/group/library@v0.1.0: verifying go.mod: our-domain.com/group/library@v0.1.0/go.mod: reading https://sum.golang.org/lookup/our-domain.com/group/library@v0.1.0: 410 Gone
        server response: not found: our-domain.com/group/library@v0.1.0: unrecognized import path "our-domain.com/group/library": https fetch: Get "https://our-domain.com/group/library?go-get=1": dial tcp: lookup our-domain.com on 8.8.8.8:53: no such host

It works if I'm building inside docker with adding dns to /etc/docker/daemon.json

{ "dns": ["1.2.3.4"] }

How to do it for getting dependency locally?
Running on MacOs with go1.13

I tried to add DNS address to the Network settings but go get still doesn't use it.

答案1

得分: 5

尝试设置 GOPRIVATE=our-domain.com

go env -w GOPRIVATE=our-domain.com

否则,该命令将尝试使用 Go 代理和校验和数据库解析该名称。

英文:

Try set GOPRIVATE=our-domain.com.

go env -w GOPRIVATE=our-domain.com

Otherwise the command tries to resolve the name using the Go proxy and checksum db.

huangapple
  • 本文由 发表于 2021年9月30日 17:03:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/69389366.html
匿名

发表评论

匿名网友

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

确定