因?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是世界上最好的語言沒有之一