source

package
v0.0.0-...-ec48b64 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2023 License: Apache-2.0, BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(timeout time.Duration) *Client

New constructs a *Client using the provided timeout.

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 ModuleInfo

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

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

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

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

func (*Info) FileURL

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) SetCommit

func (i *Info) SetCommit(commit string)

SetCommit overrides commit to a specified commit. Usually, you should pass your version to ModuleInfo(). However, when you do not know the version and just wants a link that points to a known commit/branch/tag. You can use this method to directly override the commit like info.SetCommit("master").

Note this is different from directly passing "master" as version to ModuleInfo(), because for modules not at the root of a repo, there are conventions that add a module's relative dir in front of the version as the actual git tag. For example, for a sub module at ./submod whose version is v1.0.1, the actual git tag should be submod/v1.0.1.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL