簡體   English   中英

通過不帶SSL的HTTP將Go模塊與私有存儲庫一起使用

[英]Using Go modules with private repositories via HTTP without SSL

有沒有一種方法可以強制go命令使用HTTP而不是HTTPS?

我正在嘗試將項目移至Go Modules,但是該項目包括一個私有git存儲庫作為依賴項。 這個git倉庫托管在防火牆后面的專用LAN中,我通常使用cd $GOPATH/git.ourdomain.net/foo/bar/ && git clone http://my-user:my-password@git.ourdomain.net/foo/bar/reponame.git

但是,現在命令go modgo getgo test試圖將HTTP與SSL(HTTPS)結合使用。

此設置無濟於事:

git config \
  --global \
  url."http://my-user:my-password@git.ourdomain.net/foo/bar/reponame".insteadOf \
  "http://git.ourdomain.net"

(在此處檢查有關私有存儲庫的git設置的一些上下文: https : //medium.com/cloud-native-the-gathering/go-modules-with-private-git-repositories-dfe795068db4

我已經修改了文件go.mod以包含對該私有存儲庫的引用(使用類似git.ourdomain.net/foo/bar/reponame@v0.0.0-<YYYYMMDDHHmmSS>-<GIT_COMMIT_ID> ),但是在調用時用包含該私有存儲go.mod的文件go.mod go test ,然后我看到:

go: git.ourdomain.net/foo/bar/reponame@v0.0.0-<YYYYMMDDHHmmSS>-<GIT_COMMIT_ID>: unrecognized import path "git.ourdomain.net/foo/bar/reponame" (https fetch: Get https://git.ourdomain.net/foo/bar/reponame?go-get=1: dial tcp <PUBLIC_IP_ADDRESS>:443: connect: connection refused)

我還嘗試將go.mod還原為原始版本(沒有該私有存儲庫),並嘗試從文件go.mod的存儲路徑中go get數據,假設這樣做會通過HTTP更新go.mod文件,因為-insecure (在此處查看https://golang.org/cmd/go/#hdr-Module_aware_go_get ),例如:

GO111MODULE=on go get -insecure -u git.ourdomain.net/foo/bar/reponame

但這給出了錯誤信息:

fatal: remote error: Repository not found
The requested repository does not exist, or you do not have permission to
access it.

我知道我應該使用SSL,但是我從未在此git服務器上控制過以應配置方式配置它。 因此,我只是使用git clone提供一個HTTP URL(在防火牆后面時),並且它始終有效。

go命令通過將路徑解析為版本控制位置來開始獲取給定的模塊路徑。 為了解析路徑,它發出HTTPS請求並按照https://tip.golang.org/cmd/go/#hdr-中的說明查找<meta name="go-import" […]>標記。 Remote_import_paths

如果希望它跳過該步驟,則必須使用版本控制后綴(在同一文檔中列出)來指示導入路徑是原始版本控制路徑。

如果您編寫的是import "git.ourdomain.net/foo/bar/reponame.git"而不是import "git.ourdomain.net/foo/bar/reponame" ,則應該發現最初的HTTPS解析已跳過,隨后的git操作使用全局git配置中的而insteadOf聲明。

暫無
暫無

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

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