猿问

为什么去模块ssh自定义私有存储库(非github)配置仍然请求https获取?

我正在使用Go模块。

为了使用模块版本,我不能使用本地模块。例如:

replace locakpkg => ../localpkg v0.1.0

上述操作将失败,因为到目前为止,替换本地路径无法有版本(转到 1.15)。

因此,为了使模块版本正常工作,我决定使用私有ssh存储库。

我确实搜索了如何使私有ssh存储库工作两天。

通过关注许多在线文章,我做到了

git config --global url.user@private.com:.insteadOf https://private.com/go env -w GOPRIVATE=private.com

我发现go get总是会做https fetch来检查ssl凭证。所以我也正确地配置了一个https服务器。

但最终,我仍然收到一条错误消息:

unrecognized import path "private.com/foo": reading https://private.com/foo?go-get=1: 404 Not Found

我确实谷歌了这个错误,并发现了这个规范 https://golang.org/ref/mod#vcs-find 它说我必须让服务器回复https获取请求。<meta name="go-import" content="root-path vcs repo-url">

  • 如果有一种方法可以在本地模块包中使用git标签版本控制,我可以在go.mod中使用本地替换,而不是配置私有ssh存储库。

  • 如果以上几点无法实现,那么在配置私有 ssh 存储库时如何避免 https 获取?我认为ssh repo与https协议无关。


慕森卡
浏览 168回答 1
1回答

蝴蝶刀刀

(我在 Linux 上使用 go 1.15。发布此答案时的最新稳定版本)我解决了这个问题并在这里发帖,希望有一天这会帮助其他人。我在网上搜索没有找到任何正确的答案。简而言之,答案是在所有地方都使用后缀。不带后缀,将使用代替 (git)。.git.gitgo mod tidygo gethttpsssh在客户端:该文件(在 linux 上)如果您在服务器上使用 path:~/.gitconfig/repopath/foo.git[url&nbsp;"ssh://user@private.com"] &nbsp;&nbsp;&nbsp;&nbsp;insteadOf&nbsp;=&nbsp;https://private.com该文件(在 linux 上)如果您在服务器上使用 path:~/.gitconfig~/repopath/foo.git[url&nbsp;"user@private.com:"] &nbsp;&nbsp;&nbsp;&nbsp;insteadOf&nbsp;=&nbsp;https://private.com/执行以下命令以在 Linux 上进行更新:~/.config/go/envgo&nbsp;env&nbsp;-w&nbsp;GOPRIVATE=private.com在 中,它应该使用go.modrequire&nbsp;private.com/repopath/foo.git&nbsp;v0.1.0在 中,它应该是file.goimport&nbsp;private.com/repopath/foo.git在 SSH 服务器上在私有服务器上应该有:foo.git/go.modmodule&nbsp;private.com/repopath/foo.git并确保服务器上的 git 存储库具有 标记版本 。不要忘记在客户端使用将标签版本更新到服务器。没有 ,则不会推送标记版本。v0.1.0git push --tags--tags在添加后缀到所有必需的位置后,将不再发送https请求。.gitgo mod tidygo get
随时随地看视频慕课网APP

相关分类

Go
我要回答