突然间使用 glide get 开始出错,错误信息为
Failed to checkout packages: Cannot detect VCS
研究了一下 glide 的源代码,定位到 vcs_remote_lookup.go 中 detectVcsFromRemote 函数,当我们使用 glide get golang.org/x/net 时,会下载 "https://golang.org/x/net" 页面,并从中解析出代码所在的确切位置,如果 golang.org 被墙或网络不稳定就会报这个错,可以使用 curl 进行验证。
正常情况下:
$ curl https://golang.org/x/net
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="golang.org/x/net git https://go.googlesource.com/net">
<meta name="go-source" content="golang.org/x/net https://github.com/golang/net/ https://github.com/golang/net/tree/master{/dir} https://github.com/golang/net/blob/master{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url=https://godoc.org/golang.org/x/net">
</head>
<body>
Nothing to see here; <a href=" ">move along</a >.
</body>
</html>
网络不稳定时:
$ curl https://golang.org/x/net curl: (7) Failed to connect to golang.org port 443: Connection timed out
对于这种问题只能是等待网站恢复正常访问,紧急情况下,可以修改 glide.yaml ,在相应 package 下手工指定 repo 为具体的代码仓库地址,如:
- package: golang.org/x/net repo: https://go.googlesource.com/net vcs: git