英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论