Documentation ¶
Index ¶
- Variables
- func ApplyModuleGraph(moduleDir string, modules []Module) error
- func GetLatestTag(repo *git.Repository, headCommit *object.Commit) (*tag, error)
- func GetModuleVersion(moduleDir string) (string, error)
- func GetVersionFromTag(moduleDir string) (string, error)
- func IsModule(dir string) bool
- func IsVendoring(moduleDir string) bool
- func ResolveLocalReplacements(mainModuleDir string, modules []Module) error
- type Module
- func FilterModules(moduleDir string, modules []Module, includeTest bool) ([]Module, error)
- func GetVendoredModules(moduleDir string, includeTest bool) ([]Module, error)
- func LoadModule(moduleDir string) (*Module, error)
- func LoadModules(moduleDir string, includeTest bool) ([]Module, error)
- func LoadModulesFromBinary(binaryPath string) (string, []Module, map[string]string, error)
- func LoadModulesFromPackages(moduleDir, packagePattern string) ([]Module, error)
- type ModuleDownload
- type Package
- type PackageError
Constants ¶
This section is empty.
Variables ¶
var ErrNoModule = errors.New("not a go module")
ErrNoModule indicates that a given path is not a valid Go module
var ErrNotVendoring = errors.New("the module is not vendoring its dependencies")
Functions ¶
func ApplyModuleGraph ¶ added in v1.0.0
func GetLatestTag ¶ added in v1.0.0
GetLatestTag determines the latest tag relative to HEAD. Only tags with valid semver are considered.
func GetModuleVersion ¶ added in v0.3.0
GetModuleVersion attempts to detect a given module's version.
If no Git repository is found in moduleDir, directories will be traversed upwards until the root directory is reached. This is done to accommodate for multi-module repositories, where modules are not placed in the repo root.
func GetVersionFromTag ¶
GetVersionFromTag checks if the HEAD commit is annotated with a tag and if it is, returns that tag's name. If the HEAD commit is not tagged, a pseudo version will be generated and returned instead.
func IsVendoring ¶ added in v1.0.0
IsVendoring determines whether of not the module at moduleDir is vendoring its dependencies.
func ResolveLocalReplacements ¶ added in v1.0.0
ResolveLocalReplacements tries to resolve paths and versions for local replacement modules.
Types ¶
type Module ¶
type Module struct { Path string // module path Version string // module version Replace *Module // replaced by this module Main bool // is this the main module? Indirect bool // is this module only an indirect dependency of main module? Dir string // directory holding files for this module, if any Dependencies []*Module `json:"-"` // modules this module depends on Local bool `json:"-"` // is this a local module? TestOnly bool `json:"-"` // is this module only required for tests? Vendored bool `json:"-"` // is this a vendored module? Files []string `json:"-"` // files in this module }
See https://golang.org/ref/mod#go-list-m
func FilterModules ¶ added in v1.0.0
FilterModules queries `go mod why` with all provided modules to determine whether or not they're required by the main module. Modules required by the main module are returned in a new slice.
Unless includeTest is true, test-only dependencies are not included in the returned slice. Test-only modules will have the TestOnly field set to true.
Note that this method doesn't work when replacements have already been applied to the module slice. Consider a go.mod file containing the following lines:
require golang.org/x/crypto v0.0.0-xxx-xxx replace golang.org/x/crypto => github.com/ProtonMail/go-crypto v0.0.0-xxx-xxx
Querying `go mod why -m` with `golang.org/x/crypto` yields the expected result, querying it with `github.com/ProtonMail/go-crypto` will always yield `(main module does not need github.com/ProtonMail/go-crypto)`. See:
func GetVendoredModules ¶ added in v1.0.0
func LoadModule ¶ added in v1.0.0
func LoadModules ¶ added in v1.0.0
func LoadModulesFromBinary ¶ added in v1.0.0
func LoadModulesFromPackages ¶ added in v1.0.0
func (Module) Coordinates ¶ added in v0.2.0
func (Module) PackageURL ¶
type ModuleDownload ¶ added in v1.0.0
type ModuleDownload struct { Path string // module path Version string // module version Error string // error loading module Dir string // absolute path to cached source root directory Sum string // checksum for path, version (as in go.sum) }
See https://golang.org/ref/mod#go-mod-download
func Download ¶ added in v1.0.0
func Download(modules []Module) ([]ModuleDownload, error)
func (ModuleDownload) Coordinates ¶ added in v1.0.0
func (m ModuleDownload) Coordinates() string
type Package ¶ added in v1.0.0
type Package struct { Dir string // directory containing package sources ImportPath string // import path of package in dir Name string // package name Standard bool // is this package part of the standard Go library? Module *Module // info about package's containing module, if any (can be nil) GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) CgoFiles []string // .go source files that import "C" CFiles []string // .c source files CXXFiles []string // .cc, .cxx and .cpp source files MFiles []string // .m source files HFiles []string // .h, .hh, .hpp and .hxx source files FFiles []string // .f, .F, .for and .f90 Fortran source files SFiles []string // .s source files SwigFiles []string // .swig files SwigCXXFiles []string // .swigcxx files SysoFiles []string // .syso object files to add to archive EmbedFiles []string // files matched by EmbedPatterns Error *PackageError // error loading package }
See https://golang.org/cmd/go/#hdr-List_packages_or_modules
func LoadPackage ¶ added in v1.0.0
type PackageError ¶ added in v1.0.0
type PackageError struct {
Err string
}
func (PackageError) Error ¶ added in v1.0.0
func (pe PackageError) Error() string