github.com/onsi/ginkgo/v2: gitlab.sludev.shop/golang/client/im_client@v0.0.1: reading gitlab.sludev.shop/golang/client/im_client/go.mod at revision im_client/v0.0.1: git ls-remote -q http://gitlab.sludev.shop/golang/client.git in /home/x/.cache/go-mod/cache/vcs/424c2f9446a5e0ba57bef19ac5af0e43119285e8f80ee29a741abc0228a0a6f2: exit status 128:
remote: The project you were looking for could not be found or you don't have permission to view it.
fatal: repository 'http://oauth2:x@gitlab.sludev.shop/golang/client.git/' not found
gitlab.sludev.shop/golang/client.git代码通过git clone是可以拉下来的,
go mod:
gitlab.sludev.shop/golang/client/im_client v0.0.1
使用:
im_client "gitlab.sludev.shop/golang/client/im_client"
而且设置了oauth2认证,还是报错,这是怎么回事?
golang访问私有仓库没有权限或者不存在
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
阿里嘎多学长 2025-10-28 13:08关注阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程
问题分析
你在使用 GoLang 访问 GitLab 私有仓库时,遇到了权限问题或者仓库不存在的问题。
解决方案
- 检查仓库 URL 和凭证
确保 GitLab 仓库 URL 和凭证正确无误。私有仓库的 URL 格式通常为
https://gitlab.sludev.shop/golang/client/im_client.git。 - 检查 GitLab 凭证 确保你的 GitLab 凭证正确无误,包括用户名和密码或个人访问令牌。
- 检查仓库是否存在 确保仓库存在并且你有访问权限。
- 使用 GitLab 的 API
尝试使用 GitLab 的 API 来访问仓库,例如使用
gitlab-go库。
核心代码
package main import ( "context" "fmt" "log" "github.com/xanzy/go-gitlab" ) func main() { // 初始化 GitLab 客户端 gl, err := gitlab.NewClient("https://gitlab.sludev.shop", gitlab.WithToken("你的个人访问令牌")) if err != nil { log.Fatal(err) } // 获取仓库信息 repo, _, err := gl.Repositories.GetRepository(context.Background(), "golang/client/im_client") if err != nil { log.Fatal(err) } fmt.Println(repo.Name) }注意 请替换
https://gitlab.sludev.shop和"你的个人访问令牌"为你的实际 GitLab 地址和个人访问令牌。解决 无用评论 打赏 举报- 检查仓库 URL 和凭证
确保 GitLab 仓库 URL 和凭证正确无误。私有仓库的 URL 格式通常为