pkgsite: Index | Files | Directories

package internal

import ""

Package internal contains data used through x/pkgsite.


Package Files

datasource.go discovery.go experiment.go nonredist.go unit.go


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"
const (
    ExperimentDirectoryTree        = "directory-tree"
    ExperimentNotAtLatest          = "not-at-latest"
    ExperimentRedirectedFromBanner = "redirected-from-banner"
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.


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

DefaultBranches are default branches that are supported by pkgsite.

var Experiments = map[string]string{
    ExperimentDirectoryTree:        "Enable the directory tree layout on the unit page.",
    ExperimentNotAtLatest:          "Enable the display of a 'not at latest' badge.",
    ExperimentRedirectedFromBanner: "Display banner with path that request was redirected from.",

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

func SeriesPathForModule Uses

func SeriesPathForModule(modulePath string) string

SeriesPathForModule returns the series path for the provided modulePath.

func Suffix Uses

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 Uses

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.

type DataSource Uses

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.
    GetUnit(ctx context.Context, pathInfo *UnitMeta, fields FieldSet) (_ *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) (LatestInfo, error)

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

type Documentation Uses

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

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

type Experiment Uses

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 Uses

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

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

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

IndexVersion holds the version information returned by the module index.

type LatestInfo Uses

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 "", there
    // is another module path with a greater major version
    // "". This field will be
    // "" 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 Module Uses

type Module struct {
    // Licenses holds all licenses within this module version, including those
    // that may be contained in nested subdirectories.
    Licenses []*licenses.License
    Units    []*Unit

A Module is a specific, reproducible build of a module.

func (*Module) Packages Uses

func (m *Module) Packages() []*Unit

Packages returns all of the units for a module that are packages.

func (*Module) RemoveNonRedistributableData Uses

func (m *Module) RemoveNonRedistributableData()

type ModuleInfo Uses

type ModuleInfo struct {
    ModulePath        string
    Version           string
    CommitTime        time.Time
    IsRedistributable bool
    HasGoMod          bool // whether the module zip has a go.mod file
    SourceInfo        *source.Info

ModuleInfo holds metadata associated with a module.

func (*ModuleInfo) SeriesPath Uses

func (v *ModuleInfo) SeriesPath() string

SeriesPath returns the series path for the module.

A series is a group of modules that share the same base path and are assumed to be major-version variants.

The series path is the module path without the version. For most modules, this will be the module path for all module versions with major version 0 or 1. For modules, the series path does not correspond to any module version.

Examples: The module paths "a/b" and "a/b/v2" both have series path "a/b". The module paths "" and "" both have series path "".

type ModuleVersionState Uses

type ModuleVersionState struct {
    ModulePath string
    Version    string

    // IndexTimestamp is the timestamp received from the Index for this version,
    // which should correspond to the time this version was committed to the
    // Index.
    IndexTimestamp time.Time
    // CreatedAt is the time this version was originally inserted into the
    // module version state table.
    CreatedAt time.Time

    // Status is the most recent HTTP status code received from the Fetch service
    // for this version, or nil if no request to the fetch service has been made.
    Status int
    // Error is the most recent HTTP response body received from the Fetch
    // service, for a response with an unsuccessful status code. It is used for
    // debugging only, and has no semantic significance.
    Error string
    // TryCount is the number of times a fetch of this version has been
    // attempted.
    TryCount int
    // LastProcessedAt is the last time this version was updated with a result
    // from the fetch service.
    LastProcessedAt *time.Time
    // NextProcessedAfter is the next time a fetch for this version should be
    // attempted.
    NextProcessedAfter time.Time

    // AppVersion is the value of the GAE_VERSION environment variable, which is
    // set by app engine. It is a timestamp in the format 20190709t112655 that
    // is close to, but not the same as, the deployment time. For example, the
    // deployment time for the above timestamp might be Jul 9, 2019, 11:29:59 AM.
    AppVersion string

    // GoModPath is the path declared in the go.mod file.
    GoModPath string

    // NumPackages it the number of packages that were processed as part of the
    // module (regardless of whether the processing was successful).
    NumPackages *int

ModuleVersionState holds a worker module version state.

type PackageMeta Uses

type PackageMeta struct {
    Path              string
    Name              string
    Synopsis          string
    IsRedistributable bool
    Licenses          []*licenses.Metadata // metadata of applicable licenses

PackageMeta represents the metadata of a package in a module version.

func (*PackageMeta) RemoveNonRedistributableData Uses

func (p *PackageMeta) RemoveNonRedistributableData()

type PackageVersionState Uses

type PackageVersionState struct {
    PackagePath string
    ModulePath  string
    Version     string
    Status      int
    Error       string

PackageVersionState holds a worker package version state. It is associated with a given module version state.

type Readme Uses

type Readme struct {
    Filepath string
    Contents string

Readme is a README at the specified filepath.

type SearchResult Uses

type SearchResult struct {
    Name        string
    PackagePath string
    ModulePath  string
    Version     string
    Synopsis    string
    Licenses    []string

    CommitTime time.Time
    // Score is used to sort items in an array of SearchResult.
    Score float64

    // NumImportedBy is the number of packages that import PackagePath.
    NumImportedBy uint64

    // NumResults is the total number of packages that were returned for this
    // search.
    NumResults uint64
    // Approximate reports whether NumResults is an approximate count. NumResults
    // can be approximate if search scanned only a subset of documents, and
    // result count is estimated using the hyperloglog algorithm.
    Approximate bool

SearchResult represents a single search result from SearchDocuments.

type Unit Uses

type Unit struct {
    Readme          *Readme
    Documentation   *Documentation
    Subdirectories  []*PackageMeta
    Imports         []string
    LicenseContents []*licenses.License
    NumImports      int
    NumImportedBy   int

Unit represents the contents of some path in the Go package/module namespace. It might be a module, a package, both a module and a package, or none of the above: a directory within a module that has no .go files, but contains other units, licenses and/or READMEs."

func (*Unit) RemoveNonRedistributableData Uses

func (u *Unit) RemoveNonRedistributableData()

type UnitMeta Uses

type UnitMeta struct {
    // Unit level information
    Path              string
    Name              string
    IsRedistributable bool
    Licenses          []*licenses.Metadata

    // Module level information
    Version    string
    ModulePath string
    CommitTime time.Time
    SourceInfo *source.Info
    HasGoMod   bool

UnitMeta represents metadata about a unit.

func (*UnitMeta) IsCommand Uses

func (um *UnitMeta) IsCommand() bool

IsCommand reports whether the path represents a package path.

func (*UnitMeta) IsModule Uses

func (um *UnitMeta) IsModule() bool

IsModule reports whether the path represents a module path.

func (*UnitMeta) IsPackage Uses

func (um *UnitMeta) IsPackage() bool

IsPackage reports whether the path represents a package path.

type VersionMap Uses

type VersionMap struct {
    ModulePath       string
    RequestedVersion string
    ResolvedVersion  string
    GoModPath        string
    Status           int
    Error            string
    UpdatedAt        time.Time

VersionMap holds metadata associated with module queries for a version.


authPackage auth authorizes programs to make HTTP requests to the discovery site.
configPackage config resolves shared configuration for Go Discovery services, and provides functions to access this configuration.
config/dynconfigPackage dynconfig supports dynamic configuration for pkgsite services.
cookiePackage cookie is used to get and set HTTP cookies.
databasePackage database adds some useful functionality to a sql.DB.
dcensusPackage dcensus provides functionality for debug instrumentation.
derrorsPackage derrors defines internal error values to categorize the different types error semantics we support.
experimentPackage experiment provides functionality for experiments.
fetchPackage fetch provides a way to fetch modules from a proxy.
frontendPackage frontend provides functionality for running the site.
godocPackage godoc is for rendering Go documentation.
godoc/codecPackage codec implements the general-purpose part of an encoder for Go values.
godoc/dochtmlPackage dochtml renders Go package documentation into HTML.
godoc/dochtml/internal/renderPackage render formats Go documentation as HTML.
godoc/internal/docPackage doc extracts source code documentation from a Go AST.
indexPackage index provides a client for communicating with the module index.
licensesPackage licenses detects licenses and determines whether they are redistributable.
localdatasourcePackage localdatasource implements an in-memory internal.DataSource used to load and display documentation for local modules that are not available via a proxy.
logPackage log supports structured and unstructured logging with levels.
middlewarePackage middleware implements a simple middleware pattern for http handlers, along with implementations for some common middlewares.
pollerPackage poller supports periodic polling to load a value.
postgresPackage postgres provides functionality for reading and writing to the postgres database.
proxyPackage proxy provides a client for interacting with a proxy.
proxydatasourcePackage proxydatasource implements an internal.DataSource backed solely by a proxy instance.
queuePackage queue provides queue implementations that can be used for asynchronous scheduling of fetch actions.
secretsPackage secrets is used to interact with secretmanager.
sourcePackage source constructs public URLs that link to the source files in a module.
stdlibPackage stdlib supports special handling of the Go standard library.
testing/dbtestPackage dbtest supports testing with a database.
testing/htmlcheckPackage htmlcheck provides a set of functions that check for properties of a parsed HTML document.
testing/pagecheckPackage pagecheck implements HTML checkers for discovery site pages.
testing/samplePackage sample provides functionality for generating sample values of the types contained in the internal package.
testing/testhelperPackage testhelper provides shared functionality and constants to be used in Discovery tests.
versionPackage version handles version types.
workerPackage worker provides functionality for running a worker service.
xcontextPackage xcontext is a package to offer the extra functionality we need from contexts that is not available from the standard context package.

Package internal imports 8 packages (graph) and is imported by 26 packages. Updated 2021-01-26. Refresh now. Tools for package owners.