因为工作需要,我们用得都是自己搭建得git仓库,go get无法下载私有仓库,
go get -insture 倒是可以下载,但是在go mod下无法自动
网上看了一大堆文章,各种方法说得乱七八糟,不顶用,最终解决方法如下
1、代码仓库一定要使用https(非常重要)
2、使用https后go get就自动会给你提示了
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.
看到重点没有,go开发人员的工作还是做得比较仔细,连文档地址都告诉我们了,哈哈????
打开https://golang.org/doc/faq#git_https查看
这一步是不是感觉又撞墙了,无法打开????,但是没关系,我们有 godoc,执行
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
总结这段话就是说在 你的用户根目录下的.netrc文件加上git仓库登录账号就行了,是不是很简单
echo "machine 仓库地址 login 用户名 password 密码" > ~/.netrc
ok,再次执行go get 一切顺利
so —— go是世界上最好的语言没有之一
有疑问加站长微信联系(非本文作者)