git - 通过没有 SSL 的 HTTP 使用带有私有存储库的 Go 模块
问题描述
有没有办法强制go
命令使用 HTTP 而不是 HTTPS?
我正在尝试将一个项目移动到 Go Modules,但该项目包含一个私有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 get
并且go 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
有关私有存储库设置的一些上下文:https ://medium.com/cloud-native-the-gathering/go-modules-with-private-git-repositories-dfe795068db4 )
我已经修改了文件go.mod
以包含对该私有存储库的引用(使用类似的模式git.ourdomain.net/foo/bar/reponame@v0.0.0-<YYYYMMDDHHmmSS>-<GIT_COMMIT_ID>
),但是当使用包含该私有存储库go test
的文件调用时go.mod
,我看到:
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
到原始版本(没有该私有存储库)并尝试go get
从存储文件的路径恢复go.mod
,假设它将go.mod
通过 HTTP 以某种方式更新文件,因为-insecure
(查看此处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 请求并查找https://tip.golang.org/cmd/go/#hdr-Remote_import_paths<meta name="go-import" […]>
中描述的标签。
如果您希望它跳过该步骤,则必须使用版本控制后缀(在同一文档中列出)指示导入路径是原始版本控制路径。
如果你写import "git.ourdomain.net/foo/bar/reponame.git"
而不是import "git.ourdomain.net/foo/bar/reponame"
,你应该会发现最初的 HTTPS 解析被跳过,后续git
操作使用insteadOf
你全局git
配置中的声明。
推荐阅读
- python - python中的嵌套三角形与乌龟
- vue.js - Nuxt 没有在刷新/ssr 上添加 bodyAttr
- unit-testing - 从 UnitTest 跳过课程 - Visual Studio 2019
- linux - 有没有办法在 ansible 的条件过滤器中使用 if..else 逻辑?
- android - 在颤振中使用飞镖从值通知器中删除侦听器
- r - 使用数据表来屏蔽/过滤 R 中的另一个数据表
- javascript - 更改 Google 地图中的图标标记颜色
- java - 在使用 jsoup 解析时摆脱 html 属性及其值
- php - 用 PHP 切片图像 src 字符串
- angular - 为什么在尝试将引导模板集成到 Angular 应用程序中时出现此错误?