pkgsite: golang.org/x/pkgsite/internal/source Index | Files

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

Package Files

meta-tags.go source.go

type Client Uses

type Client struct {
    // contains filtered or unexported fields
}

func NewClient Uses

func NewClient(timeout time.Duration) *Client

New constructs a *Client using the provided timeout.

type Info Uses

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 ModuleInfo Uses

func ModuleInfo(ctx context.Context, client *Client, modulePath, version string) (info *Info, err error)

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

LegacyModuleInfo may fetch from arbitrary URLs, so it can be slow.

func NewGitHubInfo Uses

func NewGitHubInfo(repoURL, moduleDir, commit string) *Info

NewGitHubInfo creates a source.Info with GitHub URL templates. It is for testing only.

func NewGitLabInfo Uses

func NewGitLabInfo(repoURL, moduleDir, commit string) *Info

NewGitLabInfo creates a source.Info with GitHub URL templates. It is for testing only.

func (*Info) DirectoryURL Uses

func (i *Info) DirectoryURL(dir string) string

DirectoryURL returns a URL for a directory relative to the module's home directory.

func (*Info) FileURL Uses

func (i *Info) FileURL(pathname string) string

FileURL returns a URL for a file whose pathname is relative to the module's home directory.

func (*Info) LineURL Uses

func (i *Info) LineURL(pathname string, line int) string

LineURL returns a URL referring to a line in a file relative to the module's home directory.

func (*Info) MarshalJSON Uses

func (i *Info) MarshalJSON() (_ []byte, err error)

ToJSONForDB returns the Info encoded for storage in the database.

func (*Info) ModuleURL Uses

func (i *Info) ModuleURL() string

ModuleURL returns a URL for the home page of the module.

func (*Info) RawURL Uses

func (i *Info) RawURL(pathname string) string

RawURL returns a URL referring to the raw contents of a file relative to the module's home directory. In addition to the usual variables, it supports {repoPath}, which is the repo URL's path.

func (*Info) RepoURL Uses

func (i *Info) RepoURL() string

func (*Info) UnmarshalJSON Uses

func (i *Info) UnmarshalJSON(data []byte) (err error)

Package source imports 20 packages (graph) and is imported by 11 packages. Updated 2020-07-15. Refresh now. Tools for package owners.