Involved Source Files
Package fetch provides a way to fetch modules from a proxy.
fetchlocal.golatest.golimit.go
Package fetch provides a way to fetch modules from a proxy.
loadshedding.go
Package fetch provides a way to fetch modules from a proxy.
Package fetch provides a way to fetch modules from a proxy.
unit.go
Package-Level Type Names (total 6, in which 4 are exported)
/* sort exporteds by: | */
BadPackageError represents an error loading a package
because its contents do not make up a valid package.
This can happen, for example, if the .go files fail
to parse or declare different package names.
Errerror(*T) Error() string
*T : error
The maximum size of requests that can be processed at once. If an
incoming request would cause sizeInFlight to exceed this value, it won't
be processed.
Protects the variables below, and also serializes shedding decisions so
multiple simultaneous requests are handled properly.
// number of request currently in progress
// number of requests that were shedded
// total fetch requests ever seen
// size of requests currently in progress.
shouldShed reports whether a request of size should be shed (not processed).
Its second return value is a function that should be deferred by the caller.
(*T) stats() LoadShedStats
var zipLoadShedder *loadShedder
Package-Level Functions (total 34, in which 6 are exported)
FetchInfos returns information about all fetches in progress,
sorted by start time.
FetchLocalModule fetches a module from a local directory and process its contents
to return an internal.Module and other related information. modulePath is not necessary
if the module has a go.mod file, but if both exist, then they must match.
FetchResult.Error should be checked to verify that the fetch succeeded. Even if the
error is non-nil the result may contain useful data.
FetchModule queries the proxy or the Go repo for the requested module
version, downloads the module zip, and processes the contents to return an
*internal.Module and related information.
Even if err is non-nil, the result may contain useful information, like the go.mod path.
Callers of FetchModule must
defer fr.Defer()
immediately after the call.
GetInfo returns the result of a request to the proxy .info endpoint. If
the modulePath is "std", a request to @master will return an empty
commit time.
LatestModuleVersions uses the proxy to get information about the latest
versions of modulePath. It returns a LatestModuleVersions whose RawVersion
and CookedVersion is obtained from the proxy @v/list and @latest endpoints.
The cooked version is computed by choosing the latest version after removing
versions that are retracted in the go.mod file of the raw version.
The GoodVersion of LatestModuleVersions is not set. It should be determined
when inserting into a data source, since it depends on the contents of the
data source.
The hasGoMod function that is passed in should check if version v of the
module has a go.mod file, using a source other than the proxy (e.g. a
database). If it doesn't have enough information to decide, it should return
an error that wraps derrors.NotFound.
If a module has no tagged versions and hasn't been accessed at a
pseudo-version in a while, then the proxy's list endpoint will serve nothing
and its @latest endpoint will return a 404/410. (Example:
cloud.google.com/go/compute/metadata, which has a
v0.0.0-20181107005212-dafb9c8d8707 that @latest does not return.) That is not
a failure, but a valid state in which there is no version information for a
module, even though particular pseudo-versions of the module might exist. In
this case, LatestModuleVersions returns (nil, nil).
As a special case, the "std" module's versions are fetched from the repo (by
calling stdlib.Versions). We assume stdlib versions are never retracted, and
that there are no incompatible versions.
ZipLoadShedStats returns a snapshot of the current LoadShedStats for zip files.
createZipReader creates a zip file from a directory given a local path and
returns a zip.Reader to be passed to processZipFile. The purpose of the
function is to transform a local go module into a zip file to be processed by
existing functions.
extractDeprecatedComment looks for "Deprecated" comments in the line comments
before the module declaration. If it finds one, it returns true along with
the text after "Deprecated:". Otherwise it returns false, "".
extractPackagesFromZip returns a slice of packages from the module zip r.
It matches against the given licenses to determine the subset of licenses
that applies to each package.
The second return value says whether any packages are "incomplete," meaning
that they contained .go files but couldn't be processed due to current
limitations of this site. The limitations are:
* a maximum file size (MaxFileSize)
* the particular set of build contexts we consider (goEnvs)
* whether the import path is valid.
extractReadmesFromZip returns the file path and contents of all files from r
that are README files.
getGoModPath returns the module path from the go.mod file, as well as the contents of the file obtained from the proxy.
If modulePath is the standardl library, then the contents will be nil.
ignoredByGoTool reports whether the given import path corresponds
to a directory that would be ignored by the go tool.
The logic of the go tool for ignoring directories is documented at
https://golang.org/cmd/go/#hdr-Package_lists_and_patterns:
Directory and file names that begin with "." or "_" are ignored
by the go tool, as are directories named "testdata".
However, even though `go list` and other commands that take package
wildcards will ignore these, they can still be imported and used in
working Go programs. We continue to ignore the "." and "testdata"
cases, but we've seen valid Go packages with "_", so we accept those.
isReadme reports whether file is README or if the base name of file, with or
without the extension, is equal to expectedFile. README.go files will return
false. It is case insensitive. It operates on '/'-separated paths.
isVendored reports whether the given import path corresponds
to a Go package that is inside a vendor directory.
The logic for what is considered a vendor directory is documented at
https://golang.org/cmd/go/#hdr-Vendor_Directories.
loadFilesWithBuildContext loads all the given Go files at innerPath. It
returns the package name as it occurs in the source, a map of the ASTs of all
the Go files, and the token.FileSet used for parsing.
If there are no non-test Go files, it returns a NotFound error.
loadPackage loads a Go package by calling loadPackageWithBuildContext, trying
several build contexts in turn. It returns a goPackage with documentation
information for each build context that results in a valid package, in the
same order that the build contexts are listed. If none of them result in a
package, then loadPackage returns nil, nil.
If a package is fine except that its documentation is too large, loadPackage
returns a goPackage whose err field is a non-nil error with godoc.ErrTooLarge in its chain.
loadPackageForBuildContext loads a Go package made of .go files in
files, which should match some build context.
modulePath is stdlib.ModulePath for the Go standard library and the
module path for all other modules. innerPath is the path of the Go package
directory relative to the module root. The files argument must contain only
.go files that have been verified to be of reasonable size and that match
the build context.
It returns the package name, list of imports, the package synopsis, and the
serialized source (AST) for the package.
It returns an error with NotFound in its chain if the directory doesn't
contain a Go package or all .go files have been excluded by constraints. A
*BadPackageError error is returned if the directory contains .go files but do
not make up a valid package.
If it returns an error with ErrTooLarge in its chain, the other return values
are still valid.
mapKeyForFiles generates a value that corresponds to the given set of file
names and can be used as a map key.
It assumes the filenames do not contain spaces.
matchingFiles returns a map from file names to their contents, read from zipGoFiles.
It includes only those files that match the build context determined by goos and goarch.
moduleUnits returns all of the units in a given module, along
with the contents for those units.
moduleVersionDir formats the content subdirectory for the given
modulePath and version.
processGoModFile populates mod with information extracted from the contents of the go.mod file.
processZipFile extracts information from the module version zip.
readZipFile decompresses zip file f and returns its uncompressed contents.
The caller can check f.UncompressedSize64 before calling readZipFile to
get the expected uncompressed size of f.
limit is the maximum number of bytes to read.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.