gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 01:55:01 25 4
gpt4 key购买 nike

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

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 的阅读,我了解到:

If the import path is not a known code hosting site and also lacks a version control qualifier, the go tool attempts to fetch the import over https/http and looks for a tag in the document's HTML

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

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

什么都不返回。

进一步阅读:

The repo-root is the root of the version control system containing a scheme and not containing a .vcs qualifier.

For example,

import "example.org/pkg/foo"

will result in the following requests:

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

http://example.org/pkg/foo?go-get=1 (fallback, only with -insecure)

再次:

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

什么都不返回。

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

最佳答案

您输入的最后一条命令确实会返回数据。当我在终端中运行 curl -D --raw https://robpike.io/ivy\?go-get\=1 时,我得到以下数据:

<meta name="go-import" content="robpike.io/toy git https://github.com/robpike/toy.git"><meta name="go-import" content="robpike.io/cmd/translate git https://github.com/robpike/translate.git"><meta name="go-import" content="robpike.io/cmd/freq git https://github.com/robpike/freq.git"><meta name="go-import" content="robpike.io/cmd/hira git https://github.com/robpike/hira.git"><meta name="go-import" content="robpike.io/cmd/kana git https://github.com/robpike/kana.git"><meta name="go-import" content="robpike.io/cmd/kata git https://github.com/robpike/kata.git"><meta name="go-import" content="robpike.io/nihongo git https://github.com/robpike/nihongo.git"><meta name="go-import" content="robpike.io/cmd/typo git https://github.com/robpike/typo.git"><meta name="go-import" content="robpike.io/filter git https://github.com/robpike/filter.git"><meta name="go-import" content="robpike.io/cmd/unicode git https://github.com/robpike/unicode.git"><meta name="go-import" content="robpike.io/cmd/doc git https://github.com/robpike/doc.git"><meta name="go-import" content="robpike.io/cmd/scrub git https://github.com/robpike/scrub.git"><meta name="go-import" content="robpike.io/cmd/strings git https://github.com/robpike/strings.git"><meta name="go-import" content="robpike.io/ivy git https://github.com/robpike/ivy.git"><meta name="go-import" content="robpike.io/cmd/now git https://github.com/robpike/now.git">

这允许 go get 命令解析 git 存储库的虚路径。

关于go - 当给定一个未知的代码托管域站点时, 'go get' 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36161565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com