登录
首页 >  Golang >  Go问答

在 VPN 后,无法通过“go get”方式从 Github Enterprise 下载 go 包

来源:stackoverflow

时间:2024-03-25 17:45:33 160浏览 收藏

在使用 VPN 连接 GitHub Enterprise 时,无法通过“go get”命令下载 go 软件包。此问题可能是由于命令行工具未获得访问令牌,且 go get 使用 Google 的 DNS 服务器 8.8.8.8,该服务器无法解析 VPN 内部的域名。解决方案是设置环境变量 GOPRIVATE=*.mydomain.com,这将允许 go get 使用 VPN 内部的 DNS 服务器解析域名。

问题内容

我正在尝试下载 entreprise github 上的 go 软件包。

值得注意的是,该域在 vpn 外部不可见,但我已连接到该 vpn。

我可以使用浏览器浏览到 https://github.mydomain.com/some_repository,但我需要登录。

$ go get -v github.mydomain.com/some_repository

get "github.mydomain.com/some_repository": found meta tag get.metaimport{prefix:"github.mydomain.com/some_repository", vcs:"git", reporoot:"https://github.mydomain.com/some_repository.git"} at //github.mydomain.com/some_repository?go-get=1
go: downloading github.mydomain.com/some_repository v0.0.0
go get github.mydomain.com/some_repository: github.mydomain.com/[email protected]: verifying module: github.mydomain.com/[email protected]: reading https://sum.golang.org/lookup/github.mydomain.com/[email protected]: 410 gone
        server response: not found: github.mydomain.com/[email protected]: unrecognized import path "github.mydomain.com/some_repository": https fetch: get "https://github.mydomain.com/some_repository?go-get=1": dial tcp: lookup github.mydomain.com on 8.8.8.8:53: no such host

我最初认为这是由于命令行工具没有访问令牌,因为浏览器可以访问但不能访问 go get。我已在 entreprise github 上生成了一个令牌,并尝试通过以下方式解决此问题:

git config --local http.extraheader "PRIVATE-TOKEN: "
git config --local url."[email protected]:".insteadOf "https://github.mydomain.com/"

正如这里所解释的,但这没有帮助。

lookup github.mydomain.com 在 8.8.8.8:53 上的存在:没有这样的主机 可能是一个线索,因为 8.8.8.8 是谷歌的 dns 并且不可能工作,因为 mydomain.com 只存在于 vpn 上。如果断开 vpn 连接,则表明 mydomain.com 不存在。我不确定为什么 go get 会使用 8.8.8.8 作为 dns。

scutil --dns | grep 'nameserver\[[0-9]*\]' 列出了几个 dns 服务器,其中没有一个是 8.8.8.8,所以也许 go get 对其进行硬编码?


解决方案


看来设置环境变量 GOPRIVATE=*.mydomain.com 可以解决此问题。

本篇关于《在 VPN 后,无法通过“go get”方式从 Github Enterprise 下载 go 包》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>