| 物料 | 說(shuō)明 |
|---|---|
| git.xxxxxxx.com | 私有倉(cāng)庫(kù) |
| middle/user.git | 用戶服務(wù)模塊 |
1、給釋出的倉(cāng)庫(kù)打tag比如v0.0.1,這樣倉(cāng)庫(kù)地址就可以被識(shí)別
2、export GOPRIVATE=git.xxxxxxx.com
go build的時(shí)候系統(tǒng)就不會(huì)用GOPROXY以及不再校驗(yàn)SUM
3、調(diào)整git https===>ssh,注意username換成自己的用戶名
[url "username@git.xxxxxxx.com"]
insteadOf = https://git.xxxxxxx.com
這個(gè)問(wèn)題,google 堪稱一絕,夠任性
補(bǔ)充:go get拉取私有項(xiàng)目,遇到 404 Not Found解決辦法
利用go module進(jìn)行包管理的時(shí)候,要獲取遠(yuǎn)程倉(cāng)庫(kù)的最新包,使用go get+項(xiàng)目名獲取,提示404 Not Found,如圖:

這是由于go get在進(jìn)行獲取遠(yuǎn)程包的時(shí)候,沒(méi)有指定用戶以及密碼,導(dǎo)致沒(méi)有權(quán)限,故失敗
go get時(shí)添加“-insecure”參數(shù),如圖:

補(bǔ)充:golang 配置私有倉(cāng)庫(kù)
1. go mod 根據(jù)go.mod拉取依賴庫(kù)時(shí)
會(huì)使用https的方式。為了方便我們也可以通過(guò)配置git 全局配置來(lái)使用 ssh的方式拉取依賴,下面是配置 https轉(zhuǎn)換為ssh的方式:
git config --global url."git@gitee.com:".insteadOf https://gitee.com/
2. 配置環(huán)境變量
來(lái)指定私有倉(cāng)庫(kù),用于不走代理的方式
go env -w GOPRIVATE=gitee.com
這里配置私有倉(cāng)庫(kù)是gitee
3. 設(shè)置代理
go env -w GOPROXY=goproyx.io
1. 錯(cuò)誤一
abc@Genricde helloworld % go get -u gitee.com/abc/helloworld/v3 go: gitee.com/abc/helloworld/v3@v3.0.1-5 requires gitee.com/abc/tsab@v0.0.0-20210208082057-adbeb3ca5366: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /Users/abc/developer/golang/pkg/mod/cache/vcs/742008abb4987f237c93efc5ddde7db6dd8d1841fe94aea076046d86a92e26a7: exit status 128: fatal: could not read Username for 'https://gitee.com': terminal prompts disabled
這種錯(cuò)誤為沒(méi)有配置 git 的https轉(zhuǎn)換為 ssh
2. 錯(cuò)誤二
go: gitee.com/abc/helloworld@v0.0.0-20210121064045-46ac6dd9cdce requires gitee.com/abc/helloworld@v0.0.0-20210208023819-88ebb8c504ae/go.mod: verifying module: gitee.com/abc/helloworld@v0.0.0-20210208023819-88ebb8c504ae/go.mod: reading https://goproxy.io/sumdb/sum.golang.org/lookup/gitee.com/abc/tsab@v0.0.0-20210208023819-88ebb8c504ae: 410 Gone server response: not found: gitee.com/abc/helloworld@v0.0.0-20210208023819-88ebb8c504ae: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/742008abb4987f237c93efc5ddde7db6dd8d1841fe94aea076046d86a92e26a7: exit status 128: fatal: could not read Username for 'https://gitee.com': terminal prompts disabled
這種錯(cuò)誤是GOPRIVATE 設(shè)置錯(cuò)誤,使得go去驗(yàn)證庫(kù)的sum
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
標(biāo)簽:梅河口 汕頭 吐魯番 蘭州 欽州 雞西 重慶 銅川
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《完美解決golang go get私有倉(cāng)庫(kù)的問(wèn)題》,本文關(guān)鍵詞 完美,解決,golang,get,私有,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。