卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章35043本站已运行393

在 Windows 11 上运行 go mod tidy 时出现 gitlab 权限问题

在 windows 11 上运行 go mod tidy 时出现 gitlab 权限问题

php小编草莓发现,在使用Windows 11操作系统时,有些开发人员在运行"go mod tidy"命令时遇到了GitLab权限问题。这个问题可能导致无法正确更新模块依赖关系。为了解决这个问题,我们将在本文中为大家提供一些解决方案和建议,以确保顺利运行"go mod tidy"命令并成功更新模块。

问题内容

我能够很好地执行克隆、推送和其他 git 命令(必须存储在 windows 中的凭据管理器中)。但是当我执行 go mod tidy 时出现问题

下面是我在 windows 机器上执行 go mod tidy 时遇到的错误。看起来无法访问私有存储库。

gitlab.xxxxx.de/cxxxxs-v2/arc-lib/cxxxxs-go-lib/pkg/clients:
gitlab.xxxx.de/cxxxxs-v2/arc-lib/[email protected]: verifying
module: gitlab.xxxx.de/cxxxxs-v2/arc-lib/[email protected]:
reading
https://sum.golang.org/lookup/gitlab.xxxxx.de/cxxxxs-v2/arc-lib/[email protected]:
404 not found
    server response:
    not found: gitlab.xxxxx.de/cxxxxs-v2/arc-lib/[email protected]: invalid
version: git ls-remote -q origin in
/tmp/gopath/pkg/mod/cache/vcs/387e08be1426cc3d2399d471d4c4b55445c31d6ca639398a03889c4c3282d1d5:
exit status 128:
            fatal: could not read username for 'https://gitlab.xxxxx.de': terminal prompts disabled
    confirm the import path was entered correctly.
    if this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

我已经创建了 home 环境变量,指向与 userprofile 相同的文件夹。

还创建了 _netrc 文件,其中包含计算机、用户名和密码。 与 web gitlab 登录中使用的用户名和密码相同,工作正常。

_netrc内容:

machine gitlab.aaaaaa.de
login ranjit.kumar
password *****

我无法弄清楚如何调试它以找到根本原因并因此找到解决方案。请指导我。

解决方法

阅读https://sum.golang.org/lookup/gitlab.xxxxx.de/cidaas-v2/arc-lib/[电子邮件受保护]:404 未找到

它尝试在 go sumdb 中查找您的私有模块。由于您的模块是私有的,因此它不存在。

您应该将私有模块的 glob 模式添加到 goprivate。这样做:

go env -w GOPRIVATE=gitlab.xxxxx.de

goprivate 充当 gonoproxygonosumdb 的默认值。它告诉 go 工具直接从私有存储库(gonoproxy)下载模块,而不是使用公共校验和数据库(gonosumdb)检查模块。

有关更多信息,请参阅私有模块。

顺便说一句,如果您可以在没有 _netrc 的情况下提取或推送到存储库,则无需设置 _netrc 。设置 home 环境变量似乎也无关紧要。

卓越飞翔博客
上一篇: 如何在 Go 中嵌入第三方类型?
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏