Documentation
¶
Index ¶
Constants ¶
const ( DbgFlagVerbose dbgFlags = 1 << iota DbgFlagAll = DbgFlagVerbose )
const ErrNotFound = syscall.ENOENT
ErrNotFound is the sentinel reported when a module or package does not exist. It is the same value as github.com/goplus/mod.ErrNotFound (both are syscall.ENOENT), kept here so modfetch does not import the root mod package and create an import cycle through packages that depend on both.
Variables ¶
var ErrPkgNotFound = errors.New("cannot find module providing package")
ErrPkgNotFound is the sentinel reported by GetPkg when no module provides the requested package path. It is wrapped by the returned error, so callers can use errors.Is to tell "no such package" apart from a transient failure.
var ErrStdlibPkg = errors.New("standard-library package")
ErrStdlibPkg is wrapped by the error GetPkg returns for a standard-library import path (one whose first element has no dot). Such a path belongs to no downloadable module, so GetPkg reports it without touching the network.
Functions ¶
func Get ¶
Get resolves modPath to a specific module version, downloading it into GOMODCACHE when necessary, and reports the resolved module.
modPath may be versioned ("example.com/foo@v1.2.3") or unversioned ("example.com/foo"). An unversioned path is resolved to the latest version: Get first looks for the highest version already in GOMODCACHE and, on a cache miss, runs `go get <modPath>@latest` to download it.
By default Get consults GOMODCACHE first and only reaches the network on a cache miss. Passing noCache as true bypasses the cache lookup and always runs `go get`, which contacts the proxy/VCS to pick up a newer version; only the first noCache value is used and the rest are ignored.
The returned mod carries the resolved path and version. err is:
- errEmptyModPath when modPath is empty;
- nil when the module was found in the cache or downloaded successfully;
- ErrNotFound (== syscall.ENOENT) when the module exists in neither the cache nor upstream, so callers can use it as a sentinel to tell a genuine "no such module" apart from a transient failure.
Because `go get` writes to the caller's go.mod, prefer GetPkg (which downloads into a throwaway module) when that side effect is undesirable.
func GetPkg ¶ added in v0.9.5
GetPkg resolves the module that provides pkgPath, downloads it to GOMODCACHE the same way Get does, and reports where the package sits inside that module.
mod is the resolved module (path and version), exactly as Get would return it. relToRoot is the package path relative to the module root, using forward slashes; it is empty when pkgPath is the module root itself. The invariant is:
pkgPath == mod.Path when relToRoot == "" pkgPath == mod.Path + "/" + relToRoot otherwise
GetPkg enumerates the slash-separated prefixes of pkgPath from longest to shortest and probes each as a module. A "not found" / "gone" answer means the prefix is not a module and is skipped; any other failure (network error, 5xx, authentication, checksum problems) is a real error and is returned, so GetPkg never silently picks a shorter, wrong module. Among the prefixes that are modules and actually contain the package, the longest module path wins, which makes a /vN module and a nested module win over their unsuffixed parent.
If no prefix qualifies, the returned error wraps ErrPkgNotFound and lists the prefixes that were tried. Passing noCache bypasses the cache for the probes and the final fetch, matching Get.
Types ¶
This section is empty.