登录
首页 >  Golang >  Go问答

无法访问私有 Gitlab 仓库

来源:stackoverflow

时间:2024-03-24 22:21:44 298浏览 收藏

本文讨论了使用 Go 语言访问私有 GitLab 存储库时遇到的问题。当使用 `go get` 命令时,它会在输入密码后挂起。尝试使用 `-v` 标志时,它会显示一条关于 `get.metaimport` 的消息。尽管可以克隆存储库,但使用 `go get` 时会收到权限被拒绝的错误。作者尝试运行 `go clean -cache -modcache -i -r` 命令,但问题仍然存在。

问题内容

我想使用 go get 获取位于私有 gitlab 存储库中的包。我的go版本是go1.15.4 darwin/amd64。并且当前目录下有一个go.mod文件。

当我运行 go get -v git.xxx.com/path-to/[email protected] 时,它显示

get "git.xxx.com/path-to/package": found meta tag get.metaimport{prefix:"git.xxx.com/path-to/package", vcs:"git", reporoot:"https://git.xxx.com/path-to/package.git"} at //git.xxx.com/path-to/package?go-get=1
get "git.xxx.com/path-to": found meta tag get.metaimport{prefix:"git.xxx.com/path-to", vcs:"git", reporoot:"https://git.xxx.com/path-to.git"} at //git.xxx.com/path-to?go-get=1
enter passphrase for key '~/.ssh/id_rsa':

在我输入密码后,它会挂起几个小时而不显示任何内容。

我也尝试过-

$ sudo go get git.xxx.com/path-to/[email protected]

go get git.xxx.com/path-to/[email protected]: git.xxx.com/path-to/[email protected]: invalid version: unknown revision v0.0.3

但是存储库确实有一个标签 v0.0.3。如果我尝试不使用版本 -

$ sudo go get git.xxx.com/path-to/package

go get git.xxx.com/path-to/package: module git.xxx.com/path-to/package: git ls-remote -q origin in ~/go/pkg/mod/cache/vcs/bcb4baa8ab83c8bb452456922f12d22e1981b76bd2649d163d0c53c6: exit status 128:
    [email protected]: permission denied (publickey).
    fatal: could not read from remote repository.
    
    please make sure you have the correct access rights
    and the repository exists.

但我可以克隆这个存储库。所以我有访问权限并将其放在 ~/.gitconfig 文件中

[url "ssh://[email protected]:2222/"]
    insteadOf = https://git.xxx.com/

请注意,我的系统中一切正常(我可以使用 go get),直到我按照此博客运行此命令 go clean -cache -modcache -i -r


解决方案


我想知道为什么 git 配置中的端口?,也许不是根本原因,但你可以尝试

[url "[email protected]:"]
    insteadOf = https://gitlab.com/

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《无法访问私有 Gitlab 仓库》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>