go get如何下載私有倉庫

因?yàn)楣ぷ餍枰?,我們用得都是自己搭建得git倉庫,go get無法下載私有倉庫,
go get -insture 倒是可以下載,但是在go mod下無法自動(dòng)
網(wǎng)上看了一大堆文章,各種方法說得亂七八糟,不頂用,最終解決方法如下
1、代碼倉庫一定要使用https(非常重要)
2、使用https后go get就自動(dòng)會(huì)給你提示了

    fatal: could not read Username for 'https://xxx.com': terminal prompts disabled
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

看到重點(diǎn)沒有,go開發(fā)人員的工作還是做得比較仔細(xì),連文檔地址都告訴我們了,哈哈??
打開https://golang.org/doc/faq#git_https查看
這一步是不是感覺又撞墻了,無法打開??,但是沒關(guān)系,我們有 godoc,執(zhí)行
godoc -http :1088
瀏覽器輸入http://localhost:1088/doc/faq#git_https
查看文檔如下
Companies often permit outgoing traffic only on the standard TCP ports 80 (HTTP) and 443 (HTTPS), blocking outgoing traffic on other ports, including TCP port 9418 (git) and TCP port 22 (SSH). When using HTTPS instead of HTTP, git enforces certificate validation by default, providing protection against man-in-the-middle, eavesdropping and tampering attacks. The go get command therefore uses HTTPS for safety.

Git can be configured to authenticate over HTTPS or to use SSH in place of HTTPS. To authenticate over HTTPS, you can add a line to the $HOME/.netrc file that git consults:

machine github.com login USERNAME password APIKEY

總結(jié)這段話就是說在 你的用戶根目錄下的.netrc文件加上git倉庫登錄賬號(hào)就行了,是不是很簡單

echo "machine 倉庫地址 login 用戶名 password 密碼" > ~/.netrc

ok,再次執(zhí)行g(shù)o get 一切順利
so —— go是世界上最好的語言沒有之一

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容