"go get" 无法下载 go 包,git 存储库托管在 Github 企业(VPN 后面)

"go get" fails to download a go package, git repository hosted on a Github Entreprise (behind VPN)

我正在尝试下载 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/some_repository@v0.0.0: verifying module: github.mydomain.com/some_repository@v0.0.0: reading https://sum.golang.org/lookup/github.mydomain.com/some_repository@v0.0.0: 410 Gone
        server response: not found: github.mydomain.com/some_repository@v0.0.0: 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: <token>"
git config --local url."git@github.mydomain.com:".insteadOf "https://github.mydomain.com/"

如解释的那样 here 但这没有帮助。

lookup github.mydomain.com on 8.8.8.8:53: no such host 的存在可能是一个线索,因为 8.8.8.8 是 google 的 DNS 并且不可能工作,因为 mydomain.com 只存在于 VPN 上。如果断开与 VPN 的连接,则 mydomain.com 不存在。我不确定为什么 go get 会使用 8.8.8.8 作为 DNS。

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

似乎设置环境变量 GOPRIVATE=*.mydomain.com 解决了这个问题。