去使用ssh代替https不在github上 问题可能的解决方案

问题描述

我们有一个只能通过ssh / git访问的私有代码存储库(没有https),并且我们想在这里托管我们的go代码/模块。

首先我尝试:

git config --global url."git@code.internal.local:".insteadOf "https://code.internal.local/"

因此,以下两项工作都很好:

  • git clone git@code.internal.local:reponame.git
  • git clone https://code.internal.local/reponame

但是go get code.internal.local/reponame失败了,因为go仍然坚持尝试https:// ...而不是git。

package code.internal.local/reponame: unrecognized import path "code.internal.local/reponame": https fetch: Get "https://code.internal.local/reponame?go-get=1": dial tcp 192.168.0.5:443: i/o timeout

解决方法

问题

go get文档的"Remote import paths"部分详细介绍了您正在观察的行为。 特别是,仅通过查看远程导入路径code.internal.local/reponamego get就无法知道具体使用哪个VCS和哪个URL来真正托管该程序包。

为解决该问题,go get使用了一组HTTPS(作为后备,必须显式启用HTTP)对从指定导入路径构造的一组特殊URL的GET请求。 假定为此类调用提供服务的任何对象都能够以答复进行响应,该答复标识了要使用的VCS和存储库的URL。

可能的解决方案

如果您正在使用模块,则可以在对团队方便的地方(也可能部署了许多代理)设置专用的“模块代理”,并让团队成员使用GOPROXY环境变量指向方便的实例。有关更多信息,请参见go help modules

否则,如果您可以放置​​网络服务器来回答远程导入路径解析请求,则可以这样做; nginx和apache可以与其库存模块一起使用。

否则,您可能需要求助于手动操作。

,

我检查了我的 .gitconfig 并找到了此文件(用于 github 私人存储库)-

[url "ssh://git@github.com/"]
        insteadOf = https://github.com/

上面的配置对我有用。另外,您可以尝试在项目根目录中创建一个 .netrc 文件,但是应该将其推送到远程代码存储库。

,

我在此处发布了详细答案https://stackoverflow.com/a/65925691/348719

基本上,您应该在客户端为 .git 添加 require 后缀,在服务器添加 module 后缀。如果没有 .git 后缀,go get 将使用 https。

  • 在客户端 (go.mod)(将版本号更改为更正):
require code.internal.local/reponame.git v0.1.0

最好加上 go env -w GOPRIVATE=code.internal.local

  • 在服务器(go.mod)
module code.internal.local/reponame.git

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...