首頁  >  文章  >  後端開發  >  在 Windows 11 上執行 go mod tidy 時出現 gitlab 權限問題

在 Windows 11 上執行 go mod tidy 時出現 gitlab 權限問題

WBOY
WBOY轉載
2024-02-09 20:20:151088瀏覽

在 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 環境變數似乎也無關緊要。

以上是在 Windows 11 上執行 go mod tidy 時出現 gitlab 權限問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除