modfetch

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DbgFlagVerbose dbgFlags = 1 << iota
	DbgFlagAll              = DbgFlagVerbose
)
View Source
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

View Source
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.

View Source
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

func Get(modPath string, noCache ...bool) (mod module.Version, err error)

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

func GetPkg(pkgPath string, noCache ...bool) (mod module.Version, relToRoot string, err error)

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.

func SetDebug added in v0.11.9

func SetDebug(flags dbgFlags)

SetDebug sets debug flags.

Types

This section is empty.

Jump to

Keyboard shortcuts

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