package source
import "golang.org/x/pkgsite/internal/source"
Package source constructs public URLs that link to the source files in a module. It can be used to build references to Go source code, or to any other files in a module.
Of course, the module zip file contains all the files in the module. This package attempts to find the origin of the zip file, in a repository that is publicly readable, and constructs links to that repo. While a module zip file could in theory come from anywhere, including a non-public location, this package recognizes standard module path patterns and construct repository URLs from them, like the go command does.
Index ¶
- type Client
- type Info
- func FilesInfo(dir string) *Info
- func ModuleInfo(ctx context.Context, client *Client, modulePath, v string) (info *Info, err error)
- func NewGitHubInfo(repoURL, moduleDir, commit string) *Info
- func NewStdlibInfo(version string) (_ *Info, err error)
- func NewStdlibInfoForTest(version string) *Info
- func (i *Info) DirectoryURL(dir string) string
- func (i *Info) FileURL(pathname string) string
- func (i *Info) LineURL(pathname string, line int) string
- func (i *Info) MarshalJSON() (_ []byte, err error)
- func (i *Info) ModuleURL() string
- func (i *Info) RawURL(pathname string) string
- func (i *Info) RepoURL() string
- func (i *Info) UnmarshalJSON(data []byte) (err error)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
New constructs a *Client using the provided *http.Client.
func NewClientForTesting ¶
func NewClientForTesting() *Client
NewClientForTesting returns a Client suitable for testing. It returns the same results as an ordinary client for statically recognizable paths, but always returns a nil *Info for dynamic paths (those requiring HTTP requests).
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info holds source information about a module, used to generate URLs referring to directories, files and lines.
func FilesInfo ¶
FilesInfo returns an Info that links to a path in the server's /files namespace. The same path needs to be installed via frontend.Server.InstallFS.
func ModuleInfo ¶
ModuleInfo determines the repository corresponding to the module path. It returns a URL to that repo, as well as the directory of the module relative to the repo root.
ModuleInfo may fetch from arbitrary URLs, so it can be slow.
func NewGitHubInfo ¶
NewGitHubInfo creates a source.Info with GitHub URL templates. It is for testing only.
func NewStdlibInfo ¶
func NewStdlibInfoForTest ¶
NewStdlibInfoForTest returns a source.Info for the standard library at the given semantic version. It panics if the version does not correspond to a Go release tag. It is for testing only.
func (*Info) DirectoryURL ¶
DirectoryURL returns a URL for a directory relative to the module's home directory.
func (*Info) FileURL ¶
FileURL returns a URL for a file whose pathname is relative to the module's home directory.
func (*Info) LineURL ¶
LineURL returns a URL referring to a line in a file relative to the module's home directory.
func (*Info) MarshalJSON ¶
MarshalJSON returns the Info encoded for storage in the database.
func (*Info) ModuleURL ¶
ModuleURL returns a URL for the home page of the module.
func (*Info) RawURL ¶
RawURL returns a URL referring to the raw contents of a file relative to the module's home directory.
func (*Info) RepoURL ¶
RepoURL returns a URL for the home page of the repository.
func (*Info) UnmarshalJSON ¶
Source Files ¶
meta-tags.go source.go
- Version
- v0.0.0-20250218150137-224a1368cf02 (latest)
- Published
- Feb 18, 2025
- Platform
- linux/amd64
- Imports
- 17 packages
- Last checked
- 2 months ago –
Tools for package owners.