gpt4 book ai didi

go - 如何获取 go 包的实际存储库 url

转载 作者:行者123 更新时间:2023-12-01 20:02:38 26 4
gpt4 key购买 nike

例如,我们可以使用go get k8s.io/client-go来安装go包,但是有没有办法找出源代码URL实际上是https://github.com/kubernetes/client-go ?因为如果我直接访问 k8s.io/client-go 它会显示 404。

在这个例子中,go 客户端如何找出源代码在哪里?

最佳答案

Command go: Remote import paths:

Certain import paths also describe how to obtain the source code for the package using a revision control system.

... For code hosted on other servers, import paths may either be qualified with the version control type, or the go tool can dynamically fetch the import path over https/http and discover where the code resides from a <meta> tag in the HTML.

... 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 <head>.

The meta tag has the form:
<meta name="go-import" content="import-prefix vcs repo-root">

The import-prefix is the import path corresponding to the repository root. It must be a prefix or an exact match of the package being fetched with "go get". If it's not an exact match, another http request is made at the prefix to verify the <meta> tags match.

例如在您的情况下 go工具将查询 https://k8s.io/client-go?go-get=1 .自己检查:

curl https://k8s.io/client-go?go-get=1

响应:

<html><head>
<meta name="go-import"
content="k8s.io/client-go
git https://github.com/kubernetes/client-go">
<meta name="go-source"
content="k8s.io/client-go
https://github.com/kubernetes/client-go
https://github.com/kubernetes/client-go/tree/master{/dir}
https://github.com/kubernetes/client-go/blob/master{/dir}/{file}#L{line}">
</head></html>

如您所见,响应 HTML 文档清楚地表明代码位于 github.com/kubernetes/client-go。 .

关于go - 如何获取 go 包的实际存储库 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63105839/

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