git - 通过不带 SSL 的 HTTP 将 Go 模块与私有(private)存储库一起使用

标签 git http go go-modules

有没有办法强制go命令使用 HTTP 而不是 HTTPS?

我正在尝试将一个项目移动到 Go Modules,但是这个项目包含一个私有(private)的 git存储库作为依赖项。 这git存储库托管在防火墙后面的专用 LAN 中,我通常 用类似 cd $GOPATH/git.ourdomain.net/foo/bar/ && git clone http://my-user:my-password@git.ourdomain.net/foo/bar/reponame.git 的东西克隆它.

但是现在命令 go mod , go getgo test正在尝试将 HTTP 与 SSL (HTTPS) 结合使用。

此设置没有帮助:

git config \
  --global \
  url."http://my-user:my-password@git.ourdomain.net/foo/bar/reponame".insteadOf \
  "http://git.ourdomain.net"

(在此处查看有关 git 私有(private)存储库设置的一些上下文:https://medium.com/cloud-native-the-gathering/go-modules-with-private-git-repositories-dfe795068db4)

我已经修改了文件 go.mod包含对该私有(private)存储库的引用(使用类似 git.ourdomain.net/foo/bar/reponame@v0.0.0-<YYYYMMDDHHmmSS>-<GIT_COMMIT_ID> 的模式),但是在调用 go test 时带有一个文件 go.mod包括那个私有(private) repo ,然后我看到:

go: git.ourdomain.net/foo/bar/reponame@v0.0.0-<YYYYMMDDHHmmSS>-<GIT_COMMIT_ID>: unrecognized import path "git.ourdomain.net/foo/bar/reponame" (https fetch: Get https://git.ourdomain.net/foo/bar/reponame?go-get=1: dial tcp <PUBLIC_IP_ADDRESS>:443: connect: connection refused)

我也试过恢复 go.mod到原始版本(没有那个私有(private)存储库)并尝试 go get从文件所在的路径 go.mod被存储,假设会以某种方式更新 go.mod由于 -insecure,通过 HTTP 文件(在这里查看 https://golang.org/cmd/go/#hdr-Module_aware_go_get ),像这样:

GO111MODULE=on go get -insecure -u git.ourdomain.net/foo/bar/reponame

但这给出了错误信息:

fatal: remote error: Repository not found
The requested repository does not exist, or you do not have permission to
access it.

我知道我应该使用 SSL,但我从未控制过这个 git服务器按照应配置的方式配置它。所以我只用了 git clone提供 HTTP URL(在防火墙后面时)并且它始终有效。

最佳答案

go命令通过将该路径解析为版本控制位置来开始获取给定的模块路径。为了解析路径,它发出 HTTPS 请求并查找 <meta name="go-import" […]>标记如 https://tip.golang.org/cmd/go/#hdr-Remote_import_paths 中所述.

如果您希望它跳过该步骤,则必须使用版本控制后缀(在同一文档中列出)来指示导入路径是原始版本控制路径。

如果你写import "git.ourdomain.net/foo/bar/reponame.git"而不是 import "git.ourdomain.net/foo/bar/reponame" ,您应该会发现初始 HTTPS 解析被跳过,随后的 git操作使用 insteadOf来自全局的声明 git配置。

关于git - 通过不带 SSL 的 HTTP 将 Go 模块与私有(private)存储库一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56938451/

相关文章:

git - gitignore 是如何工作的?

java - 如何使用 Git 在 Eclipse 中设置跨平台 SWT 程序

java - 如何刷新网站直到服务器有响应?在Java中?

java - JSOUP-无法解析相对 URL

Paypal OAuth : 400 Error even after specifying Host

git - 如何强制从远程服务器 check out 最新版本?

git - git reset --soft 的倒数

command-line - 命令行参数后的 Golang 标志解析

android - GridView 使用 HTTP 响应呈现很长时间

go - golang 中的 websocket 服务器打开文件过多错误