internal

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package internal contains data used through x/pkgsite.

Index

Constants

View Source
const (
	// LatestVersion signifies the latest available version in requests to the
	// proxy client.
	LatestVersion = "latest"

	// MainVersion represents the main branch.
	MainVersion = "main"

	// MasterVersion represents the master branch.
	MasterVersion = "master"

	// UnknownModulePath signifies that the module path for a given package
	// path is ambiguous or not known. This is because requests to the
	// frontend can come in the form of <import-path>[@<version>], and it is
	// not clear which part of the import-path is the module path.
	UnknownModulePath = "unknownModulePath"
)
View Source
const (
	ExperimentEnableStdFrontendFetch = "enable-std-frontend-fetch"
	ExperimentVectorSearch           = "vector-search"
)
View Source
const All = "all"

All represents all values for a build context element (GOOS or GOARCH).

View Source
const StringFieldMissing = "!MISSING"

StringFieldMissing is the value for string fields that are not present in a struct. We use it to distinguish a (possibly valid) empty string from a field that was never populated.

Variables

View Source
var (
	BuildContextAll     = BuildContext{All, All}
	BuildContextLinux   = BuildContext{"linux", "amd64"}
	BuildContextWindows = BuildContext{"windows", "amd64"}
	BuildContextDarwin  = BuildContext{"darwin", "amd64"}
	BuildContextJS      = BuildContext{"js", "wasm"}
)

BuildContexts are the build contexts we check when loading a package (see internal/fetch/load.go). We store documentation for all of the listed contexts.

The order of this slice determines the precedence when multiple build contexts match a request. For example, if a user provides no GOOS or GOARCH, the first context in this list that is available in the database will be chosen as the default (typically linux/amd64).

View Source
var DefaultBranches = map[string]bool{
	MainVersion:   true,
	MasterVersion: true,
}

DefaultBranches are default branches that are supported by pkgsite.

View Source
var Experiments = map[string]string{
	ExperimentEnableStdFrontendFetch: "Enable frontend fetching for module std.",
	ExperimentVectorSearch:           "Enable hybrid vector search for package queries.",
}

Experiments represents all of the active experiments in the codebase and a description of each experiment.

View Source
var TopLevelDomains = map[string]bool{}/* 176 elements not displayed */

TopLevelDomains contains all of the top level domains in the discovery database.

Functions

func CandidateModulePaths

func CandidateModulePaths(fullPath string) []string

CandidateModulePaths returns the potential module paths that could contain the fullPath, from longest to shortest. It returns nil if no valid module paths can be constructed.

func CompareBuildContexts

func CompareBuildContexts(c1, c2 BuildContext) int

CompareBuildContexts returns a negative number, 0, or a positive number depending on the relative positions of c1 and c2 in BuildContexts.

func GOROOT

func GOROOT() string

GOROOT returns the value of GOROOT. It is similar to runtime.GOROOT but will work even if the binary is moved to a different machine. (runtime.GOROOT is deprecated since 1.24 for that reason.)

func IsGoPkgInPathElement

func IsGoPkgInPathElement(p string) bool

IsGoPkgInPathElement reports whether p is an element of a gopkg.in path. It returns true if p has "gopkg.in" as a prefix, or the suffix is a major version, for example "yaml.v2".

func MajorVersionForModule

func MajorVersionForModule(modulePath string) string

MajorVersionForModule returns the final "vN" from the module path, if any. It returns the empty string if the module path is malformed. Examples:

"m.com" => ""
"m.com/v2" => "v2"
"gpkg.in/m.v1 = "v1"

func NewContextWithRequestInfo

func NewContextWithRequestInfo(ctx context.Context, ri *RequestInfo) context.Context

NewContextWithRequestInfo creates a new context from ctx that adds the trace ID.

func ReadFileLines

func ReadFileLines(filename string) (lines []string, err error)

ReadFileLines reads and returns the lines from a file. Whitespace on each line is trimmed. Blank lines and lines beginning with '#' are ignored.

func RequestState

func RequestState(ctx context.Context, s string) func()

RequestState sets the State field of the current request. It returns a function that restores the value of the field. Typical use:

defer RequestState(ctx, "frobbing")()

func SeriesPathAndMajorVersion

func SeriesPathAndMajorVersion(modulePath string) (string, int)

SeriesPathAndMajorVersion splits modulePath into a series path and a numeric major version. If the path doesn't have a "vN" suffix, it returns 1. If the module path is invalid, it returns ("", 0).

func SeriesPathForModule

func SeriesPathForModule(modulePath string) string

SeriesPathForModule returns the series path for the provided modulePath.

func Suffix

func Suffix(fullPath, basePath string) string

Suffix returns the suffix of the fullPath. It assumes that basePath is a prefix of fullPath. If fullPath and basePath are the same, the empty string is returned.

func V1Path

func V1Path(fullPath, modulePath string) string

V1Path returns the path for version 1 of the package whose import path is fullPath. If modulePath is the standard library, then V1Path returns fullPath.

func VCSHostWithThreeElementRepoName

func VCSHostWithThreeElementRepoName(hostname string) bool

VCSHostWithThreeElementRepoName returns true when the hostname has three elements like hostname/account/project.

Types

type BuildContext

type BuildContext struct {
	GOOS, GOARCH string
}

A BuildContext describes a build context for the Go tool: information needed to build a Go package. For our purposes, we only care about the information that affects documentation generated from the package.

func MatchingBuildContext

func MatchingBuildContext(bcs []BuildContext, bc BuildContext) (BuildContext, bool)

MatchingBuildContext returns the best BuildContext from the given bcs that matches bc, according to CompareBuildContexts. It returns zero BuildContext and false if no match is found.

func SortedBuildContexts

func SortedBuildContexts(bcs []BuildContext) []BuildContext

SortedBuildContexts returns a copy of the given slice of BuildContexts, sorted by precedence according to CompareBuildContexts.

func (BuildContext) Match

func (pattern BuildContext) Match(target BuildContext) bool

Match reports whether its receiver, which acts like a pattern, matches its target, an ordinary BuildContext. In addition to the usual values, a pattern can have an empty GOOS or GOARCH, which means "match anything."

func (BuildContext) String

func (b BuildContext) String() string

String returns a string formatted representation of the build context.

type DataSource

type DataSource interface {

	// GetNestedModules returns the latest major version of all nested modules
	// given a modulePath path prefix.
	GetNestedModules(ctx context.Context, modulePath string) ([]*ModuleInfo, error)
	// GetUnit returns information about a directory, which may also be a
	// module and/or package. The module and version must both be known.
	// The BuildContext selects the documentation to read.
	GetUnit(ctx context.Context, pathInfo *UnitMeta, fields FieldSet, bc BuildContext) (_ *Unit, err error)
	// GetUnitMeta returns information about a path.
	GetUnitMeta(ctx context.Context, path, requestedModulePath, requestedVersion string) (_ *UnitMeta, err error)
	// GetModuleReadme gets the readme for the module.
	GetModuleReadme(ctx context.Context, modulePath, resolvedVersion string) (*Readme, error)
	// GetLatestInfo gets information about the latest versions of a unit and module.
	// See LatestInfo for documentation.
	GetLatestInfo(ctx context.Context, unitPath, modulePath string, latestUnitMeta *UnitMeta) (LatestInfo, error)
	// GetPathVersions returns a list of versions for the given path.
	GetPathVersions(ctx context.Context, path, start string, limit int, versionTypes ...version.Type) (_ []*ModuleInfo, next string, err error)
	// GetModulePackages returns a list of packages in the given module version.
	GetModulePackages(ctx context.Context, modulePath, version string) ([]*PackageMeta, error)
	// GetSymbols returns symbols for the given unit and build context.
	GetSymbols(ctx context.Context, pkgPath, modulePath, version string, bc BuildContext) ([]*Symbol, error)
	// GetImportedBy returns the paths of packages that import the given package.
	GetImportedBy(ctx context.Context, pkgPath, modulePath string, start string, limit int) ([]string, error)
	// GetImportedByCounts returns the counts of packages and modules that import the given package.
	GetImportedByCounts(ctx context.Context, pkgPath, modulePath string) (ImportedByCounts, error)

	// SearchSupport reports the search types supported by this datasource.
	SearchSupport() SearchSupport
	// Search searches for packages matching the given query.
	Search(ctx context.Context, q string, opts SearchOptions) (_ []*SearchResult, err error)
}

DataSource is the interface used by the frontend to interact with module data.

type Documentation

type Documentation struct {
	// The values of the GOOS and GOARCH environment variables used to parse the
	// package.
	GOOS     string
	GOARCH   string
	Synopsis string
	Source   []byte // encoded ast.Files; see godoc.Package.Encode
	API      []*Symbol
}

Documentation is the rendered documentation for a given package for a specific GOOS and GOARCH.

func DocumentationForBuildContext

func DocumentationForBuildContext(docs []*Documentation, bc BuildContext) *Documentation

DocumentationForBuildContext returns the Documentation from the list that matches the BuildContext and has the highest precedence according to CompareBuildContexts. It returns nil if no match is found. Empty BuildContext fields act as wildcards.

func (*Documentation) BuildContext

func (d *Documentation) BuildContext() BuildContext

BuildContext returns the BuildContext for d.

type Experiment

type Experiment struct {

	// Name is the name of the feature.
	Name string

	// Rollout is the percentage of requests enrolled in the experiment.
	Rollout uint

	// Description provides a description of the experiment.
	Description string
}

Experiment holds data associated with an experimental feature for frontend or worker.

type FieldSet

type FieldSet int64

A FieldSet is a bit set of struct fields. It is used to avoid reading large struct fields from the data store. FieldSet is also the type of the individual bit values. (Think of them as singleton sets.)

MinimalFields (the zero value) is the empty set. AllFields is the set containing every field.

FieldSet bits are unique across the entire project, because some types are concatenations (via embedding) of others. For example, a

const (
	WithMain FieldSet = 1 << iota
	WithImports
	WithLicenses
	WithDocsSource
)

FieldSet bits for fields that can be conditionally read from the data store.

const AllFields FieldSet = -1

AllFields is the FieldSet that contains all fields.

const MinimalFields FieldSet = 0

MinimalFields is the empty FieldSet.

type ImportedByCounts added in v0.6.0

type ImportedByCounts struct {
	Packages          int
	PackagesUpdatedAt time.Time
	Modules           int
	ModulesUpdatedAt  time.Time
}

ImportedByCounts contains counts of packages and modules that import a particular package, along with the times they were last updated in the DB. A zero time means the count was never updated.

type IndexVersion

type IndexVersion struct {
	Path      string
	Version   string
	Timestamp time.Time
}

IndexVersion holds the version information returned by the module index.

type LatestInfo

type LatestInfo struct {
	// MinorVersion is the latest minor version for the unit, regardless of
	// module.
	MinorVersion string

	// MinorModulePath is the module path for MinorVersion.
	MinorModulePath string

	// UnitExistsAtMinor is whether the unit exists at the latest minor version
	// of the module
	UnitExistsAtMinor bool

	// MajorModulePath is the path of the latest module path in the series.
	// For example, in the module path "github.com/casbin/casbin", there
	// is another module path with a greater major version
	// "github.com/casbin/casbin/v3". This field will be
	// "github.com/casbin/casbin/v3" or the input module path if no later module
	// path was found.
	MajorModulePath string

	// MajorUnitPath is the path of the unit in the latest major version of the
	// module, if it exists. For example, if the module is M, the unit is M/U,
	// and the latest major version is 3, then is field is "M/v3/U". If the module version
	// at MajorModulePath does not contain this unit, then it is the module path."
	MajorUnitPath string
}

LatestInfo holds information about the latest versions and paths. The information is relative to a unit in a module.

type LatestModuleVersions

type LatestModuleVersions struct {
	ModulePath    string
	RawVersion