当给定一个未知的代码托管域站点时,“go get”如何工作?

让我们举个例子。下面的命令将执行:

go get robpike.io/ivy

这将使我获得 $GOPATH/src 下存储库的内容。伟大的!

现在,它是如何工作的?

首先,robpike.io/ivy 回复 HTTP 重定向:

HTTP/1.1 302 Found

<a href="http://godoc.org/robpike.io/ivy">Found</a>

通过阅读go help importpath,我了解到:

如果导入路径不是已知的代码托管站点并且也缺少版本控制限定符,go 工具会尝试通过 https/http 获取导入并在文档的 HTML 中查找标记

但是,使用以下命令在重定向页面的内容中查找元标记:

curl -D --raw https://godoc.org/robpike.io/ivy | grep go-import

什么都不返回。

进一步阅读:

repo-root 是包含方案但不包含 .vcs 限定符的版本控制系统的根。

例如,

导入“example.org/pkg/foo”

将导致以下请求:

https://example.org/pkg/foo?go-get=1(首选)

http://example.org/pkg/foo?go-get=1 (后备,仅适用于 -insecure)

再次:

curl -D --raw https://robpike.io/ivy?go-get=1

什么都不返回。

所以问题是:我怎样才能像 Rob Pike 先生一样做同样的事情,并通过go get命令使用我自己的网站?


守候你守候我
浏览 196回答 2
2回答

九州编程

您输入的最后一个命令会返回数据。当我curl -D --raw https://robpike.io/ivy\?go-get\=1在终端中运行时,我得到以下数据:<meta&nbsp;name="go-import"&nbsp;content="robpike.io/toy&nbsp;git&nbsp;https://github.com/robpike/toy.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/translate&nbsp;git&nbsp;https://github.com/robpike/translate.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/freq&nbsp;git&nbsp;https://github.com/robpike/freq.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/hira&nbsp;git&nbsp;https://github.com/robpike/hira.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/kana&nbsp;git&nbsp;https://github.com/robpike/kana.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/kata&nbsp;git&nbsp;https://github.com/robpike/kata.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/nihongo&nbsp;git&nbsp;https://github.com/robpike/nihongo.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/typo&nbsp;git&nbsp;https://github.com/robpike/typo.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/filter&nbsp;git&nbsp;https://github.com/robpike/filter.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/unicode&nbsp;git&nbsp;https://github.com/robpike/unicode.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/doc&nbsp;git&nbsp;https://github.com/robpike/doc.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/scrub&nbsp;git&nbsp;https://github.com/robpike/scrub.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/strings&nbsp;git&nbsp;https://github.com/robpike/strings.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/ivy&nbsp;git&nbsp;https://github.com/robpike/ivy.git"><meta&nbsp;name="go-import"&nbsp;content="robpike.io/cmd/now&nbsp;git&nbsp;https://github.com/robpike/now.git">这允许 go get 命令解析 git 存储库的虚路径。

梵蒂冈之花

该命令curl -D --raw 'https://robpike.io/ivy?go-get=1'返回一个包含标签的 HTML 文档<meta&nbsp;name="go-import"&nbsp;content="robpike.io/ivy&nbsp;git&nbsp;https://github.com/robpike/ivy.git">该go get命令使用此元标记来解析实际 git 存储库的虚导入路径。你也可以做到的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go