Reputation: 51
For example, we can use go get k8s.io/client-go
to install the go package but is there a way to figure out the source code URL is actually https://github.com/kubernetes/client-go? Because if I visit k8s.io/client-go directly it shows 404.
How does the go client figure out where the source code is in this example?
Upvotes: 3
Views: 1153
Reputation: 417622
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.
For example in your case the go
tool will query https://k8s.io/client-go?go-get=1
. Checking it ourselves:
curl https://k8s.io/client-go?go-get=1
Response:
<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>
As you can see, the response HTML document clearly indicates the code is available at github.com/kubernetes/client-go
.
Upvotes: 6