簡體   English   中英

在 golang 中導入私有 repo 時版本和 https 引用無效

[英]Invalid version and https references when importing private repo in golang

嘗試在 golang 中將私有倉庫導入為 package。 做過:

git config --global url.git@github.com:.insteadOf https://github.com/

所以理論上所有對 https 的引用都被 ssh 版本取代。

github.com/XXX/util

是我的私人倉庫,它是一個 go 模塊。

我做了一個 go 得到 -v 並得到:

[gabriel@xiridio backend]$ go get -v
go: finding module for package github.com/XXX/util
go: downloading github.com/XXX/util v0.0.0-20200411022955-454673685ff5
go: finding module for package github.com/XXX/util
main.go:12:2: github.com/XXX/util@v0.0.0-20200411022955-454673685ff5: verifying module: github.com/XXX/util@v0.0.0-20200411022955-454673685ff5: reading https://sum.golang.org/lookup/github.com/!X!X!X/util@v0.0.0-20200411022955-454673685ff5: 410 Gone
        server response:
        not found: github.com/XXX/util@v0.0.0-20200411022955-454673685ff5: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/f1fdc5cc42a6995f954688df06783c05d28e4a60e9aaf6930a88a2487b913907: exit status 128:
                fatal: could not read Username for 'https://github.com': terminal prompts disabled

看起來有一個“版本”問題,並且由於某種原因仍然引用了 https。 我還可以做些什么?

為了能夠使用go 1.18拉出我的私有模塊,我必須做兩件事:

  1. 相當於@VonC 的答案,在我的~/.gitconfig中添加了以下兩行:
[url "ssh://git@github.com/"]
        insteadOf = https://github.com/
  1. 將我的每個私有模塊 git 路徑顯式添加到 GOPRIVATE 變量:
go env -w GOPRIVATE="github.com/projname/mod1,github.com/projname/mod2,github.com/projname/mod3"

我認為這是必要和充分的,或者至少是足夠的。

請注意,您需要使用 ssh 對您的私人存儲庫進行本地訪問才能正常工作。

可以肯定的是,我更喜歡在 git 配置命令中使用引號:

git config --global url."git@github.com:".insteadOf "https://github.com/"

以這個要點為例

這包括:

使用git@github.com的替代方法是在您的 GitHub 帳戶上生成個人訪問令牌,授予其 repo 訪問權限,然后使用以下命令代替:

 git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

還要檢查“ go get results in 'terminal prompts disabled' error for GitHub private repo ”,其中提到了GOPRIVATE的使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM