package modload
import "cmd/go/internal/modload"
Index ¶
- Variables
- func AllowWriteGoMod()
- func Allowed(m module.Version) bool
- func BinDir() string
- func BuildList() []module.Version
- func DirImportPath(dir string) string
- func DisallowWriteGoMod()
- func Enabled() bool
- func FindModulePath(dir string) (string, error)
- func FindModuleRoot(dir, limit string, legacyConfigOK bool) (root, file string)
- func HasModRoot() bool
- func Import(path string) (m module.Version, dir string, err error)
- func ImportFromFiles(gofiles []string)
- func ImportMap(path string) string
- func ImportPaths(patterns []string) []*search.Match
- func Init()
- func InitGoStmt()
- func InitMod()
- func ListModules(args []string, listU, listVersions bool) []*modinfo.ModulePublic
- func LoadALL() []string
- func LoadBuildList() []module.Version
- func LoadVendor() []string
- func Lookup(path string) (dir, realPath string, err error)
- func MinReqs() mvs.Reqs
- func ModFile() *modfile.File
- func ModInfoProg(info string) []byte
- func ModRoot() string
- func ModuleInfo(path string) *modinfo.ModulePublic
- func ModuleUsedDirectly(path string) bool
- func PackageBuildInfo(path string, deps []string) string
- func PackageDir(path string) string
- func PackageModule(path string) module.Version
- func PackageModuleInfo(pkgpath string) *modinfo.ModulePublic
- func Query(path, query string, allowed func(module.Version) bool) (*modfetch.RevInfo, error)
- func QueryPackage(path, query string, allowed func(module.Version) bool) (module.Version, *modfetch.RevInfo, error)
- func ReloadBuildList() []module.Version
- func Replacement(mod module.Version) module.Version
- func Reqs() mvs.Reqs
- func SetBuildList(list []module.Version)
- func TargetPackages() []string
- func Why(path string) string
- func WhyDepth(path string) int
- func WriteGoMod()
- type ImportMissingError
Variables ¶
var ( MustUseModules = mustUseModules() Target module.Version CmdModInit bool // running 'go mod init' CmdModModule string // module argument for 'go mod init' )
ErrRequire is the sentinel error returned when Require encounters problems. It prints the problems directly to standard error, so that multiple errors can be displayed easily.
var HelpGoMod = &base.Command{ UsageLine: "go.mod", Short: "the go.mod file", Long: "" /* 3038 byte string literal not displayed */, }
var HelpModules = &base.Command{ UsageLine: "modules", Short: "modules, module versions, and more", Long: "" /* 18132 byte string literal not displayed */, }
var LoadTests bool
LoadTests controls whether the loaders load tests of the root packages.
Functions ¶
func AllowWriteGoMod ¶
func AllowWriteGoMod()
AllowWriteGoMod undoes the effect of DisallowWriteGoMod: future calls to WriteGoMod will update go.mod if needed. Note that any past calls have been discarded, so typically a call to AlowWriteGoMod should be followed by a call to WriteGoMod.
func Allowed ¶
Allowed reports whether module m is allowed (not excluded) by the main module's go.mod.
func BinDir ¶
func BinDir() string
func BuildList ¶
BuildList returns the module build list, typically constructed by a previous call to LoadBuildList or ImportPaths. The caller must not modify the returned list.
func DirImportPath ¶
DirImportPath returns the effective import path for dir, provided it is within the main module, or else returns ".".
func DisallowWriteGoMod ¶
func DisallowWriteGoMod()
DisallowWriteGoMod causes future calls to WriteGoMod to do nothing at all.
func Enabled ¶
func Enabled() bool
Enabled reports whether modules are (or must be) enabled. If modules are enabled but there is no main module, Enabled returns true and then the first use of module information will call die (usually through MustModRoot).
func FindModulePath ¶
Exported only for testing.
func FindModuleRoot ¶
Exported only for testing.
func HasModRoot ¶
func HasModRoot() bool
HasModRoot reports whether a main module is present. HasModRoot may return false even if Enabled returns true: for example, 'get' does not require a main module.
func Import ¶
Import finds the module and directory in the build list containing the package with the given import path. The answer must be unique: Import returns an error if multiple modules attempt to provide the same package. Import can return a module with an empty m.Path, for packages in the standard library. Import can return an empty directory string, for fake packages like "C" and "unsafe".
If the package cannot be found in the current build list, Import returns an ImportMissingError as the error. If Import can identify a module that could be added to supply the package, the ImportMissingError records that module.
func ImportFromFiles ¶
func ImportFromFiles(gofiles []string)
ImportFromFiles adds modules to the build list as needed to satisfy the imports in the named Go source files.
func ImportMap ¶
ImportMap returns the actual package import path for an import path found in source code. If the given import path does not appear in the source code for the packages that have been loaded, ImportMap returns the empty string.
func ImportPaths ¶
ImportPaths returns the set of packages matching the args (patterns), adding modules to the build list as needed to satisfy new imports.
func Init ¶
func Init()
Init determines whether module mode is enabled, locates the root of the current module (if any), sets environment variables for Git subprocesses, and configures the cfg, codehost, load, modfetch, and search packages for use with modules.
func InitGoStmt ¶
func InitGoStmt()
InitGoStmt adds a go statement, unless there already is one.
func InitMod ¶
func InitMod()
InitMod sets Target and, if there is a main module, parses the initial build list from its go.mod file, creating and populating that file if needed.
func ListModules ¶
func ListModules(args []string, listU, listVersions bool) []*modinfo.ModulePublic
func LoadALL ¶
func LoadALL() []string
LoadALL returns the set of all packages in the current module and their dependencies in any other modules, without filtering due to build tags, except "+build ignore". It adds modules to the build list as needed to satisfy new imports. This set is useful for deciding whether a particular import is needed anywhere in a module.
func LoadBuildList ¶
LoadBuildList loads and returns the build list from go.mod. The loading of the build list happens automatically in ImportPaths: LoadBuildList need only be called if ImportPaths is not (typically in commands that care about the module but no particular package).
func LoadVendor ¶
func LoadVendor() []string
LoadVendor is like LoadALL but only follows test dependencies for tests in the main module. Tests in dependency modules are ignored completely. This set is useful for identifying the which packages to include in a vendor directory.
func Lookup ¶
Lookup returns the source directory, import path, and any loading error for the package at path. Lookup requires that one of the Load functions in this package has already been called.
func MinReqs ¶
MinReqs returns a Reqs with minimal dependencies of Target, as will be written to go.mod.
func ModFile ¶
ModFile returns the parsed go.mod file.
Note that after calling ImportPaths or LoadBuildList, the require statements in the modfile.File are no longer the source of truth and will be ignored: edits made directly will be lost at the next call to WriteGoMod. To make permanent changes to the require statements in go.mod, edit it before calling ImportPaths or LoadBuildList.
func ModInfoProg ¶
func ModRoot ¶
func ModRoot() string
ModRoot returns the root of the main module. It calls base.Fatalf if there is no main module.
func ModuleInfo ¶
func ModuleInfo(path string) *modinfo.ModulePublic
func ModuleUsedDirectly ¶
ModuleUsedDirectly reports whether the main module directly imports some package in the module with the given path.
func PackageBuildInfo ¶
func PackageDir ¶
PackageDir returns the directory containing the source code for the package named by the import path.
func PackageModule ¶
PackageModule returns the module providing the package named by the import path.
func PackageModuleInfo ¶
func PackageModuleInfo(pkgpath string) *modinfo.ModulePublic
func Query ¶
Query looks up a revision of a given module given a version query string. The module must be a complete module path. The version must take one of the following forms:
- the literal string "latest", denoting the latest available, allowed tagged version, with non-prereleases preferred over prereleases. If there are no tagged versions in the repo, latest returns the most recent commit.
- v1, denoting the latest available tagged version v1.x.x.
- v1.2, denoting the latest available tagged version v1.2.x.
- v1.2.3, a semantic version string denoting that tagged version.
- <v1.2.3, <=v1.2.3, >v1.2.3, >=v1.2.3, denoting the version closest to the target and satisfying the given operator, with non-prereleases preferred over prereleases.
- a repository commit identifier, denoting that commit.
If the allowed function is non-nil, Query excludes any versions for which allowed returns false.
If path is the path of the main module and the query is "latest", Query returns Target.Version as the version.
func QueryPackage ¶
func QueryPackage(path, query string, allowed func(module.Version) bool) (module.Version, *modfetch.RevInfo, error)
QueryPackage looks up a revision of a module containing path.
If multiple modules with revisions matching the query provide the requested package, QueryPackage picks the one with the longest module path.
If the path is in the main module and the query is "latest", QueryPackage returns Target as the version.
func ReloadBuildList ¶
func Replacement ¶
Replacement returns the replacement for mod, if any, from go.mod. If there is no replacement for mod, Replacement returns a module.Version with Path == "".
func Reqs ¶
Reqs returns the current module requirement graph. Future calls to SetBuildList do not affect the operation of the returned Reqs.
func SetBuildList ¶
SetBuildList sets the module build list. The caller is responsible for ensuring that the list is valid. SetBuildList does not retain a reference to the original list.
func TargetPackages ¶
func TargetPackages() []string
TargetPackages returns the list of packages in the target (top-level) module, under all build tag settings.
func Why ¶
Why returns the "go mod why" output stanza for the given package, without the leading # comment. The package graph must have been loaded already, usually by LoadALL. If there is no reason for the package to be in the current build, Why returns an empty string.
func WhyDepth ¶
WhyDepth returns the number of steps in the Why listing. If there is no reason for the package to be in the current build, WhyDepth returns 0.
func WriteGoMod ¶
func WriteGoMod()
WriteGoMod writes the current build list back to go.mod.
Types ¶
type ImportMissingError ¶
func (*ImportMissingError) Error ¶
func (e *ImportMissingError) Error() string
Source Files ¶
build.go help.go import.go init.go list.go load.go query.go search.go
- Version
- v1.12.11
- Published
- Oct 17, 2019
- Platform
- linux/amd64
- Imports
- 35 packages
- Last checked
- 4 seconds ago –
Tools for package owners.