Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyModuleGraph(logger zerolog.Logger, moduleDir string, modules []Module) error
- func GetLatestTag(logger zerolog.Logger, repo *git.Repository, headCommit *object.Commit) (*tag, error)
- func GetModuleVersion(logger zerolog.Logger, moduleDir string) (string, error)
- func GetVersionFromTag(logger zerolog.Logger, moduleDir string) (string, error)
- func IsModule(dir string) bool
- func IsVendoring(moduleDir string) bool
- func ResolveLocalReplacements(logger zerolog.Logger, mainModuleDir string, modules []Module) error
- type BuildInfo
- type Module
- func FilterModules(logger zerolog.Logger, moduleDir string, modules []Module, includeTest bool) ([]Module, error)
- func GetVendoredModules(logger zerolog.Logger, moduleDir string, includeTest bool) ([]Module, error)
- func LoadModule(logger zerolog.Logger, moduleDir string) (*Module, error)
- func LoadModules(logger zerolog.Logger, moduleDir string, includeTest bool) ([]Module, error)
- func LoadModulesFromPackages(logger zerolog.Logger, moduleDir, packagePattern string) ([]Module, error)
- func LoadStdlibModule(logger zerolog.Logger) (*Module, error)
- type ModuleDownload
- type Package
- type PackageError
Constants ¶
const StdlibModulePath = "std"
StdlibModulePath defines the path used for Go's standard library module.
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
func GetLatestTag(logger zerolog.Logger, repo *git.Repository, headCommit *object.Commit) (*tag, error)
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.
Types ¶
type BuildInfo ¶ added in v1.1.0
type BuildInfo struct {
GoVersion string // Version of Go that produced this binary.
Path string // The main package path
Main *Module // The module containing the main package
Deps []Module // Module dependencies
Settings map[string]string // Other information about the build.
}
BuildInfo represents the build information read from a Go binary. Adapted from https://github.com/golang/go/blob/931d80ec17374e52dbc5f9f63120f8deb80b355d/src/runtime/debug/mod.go#L41
func LoadBuildInfo ¶ added in v1.1.0
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?
Packages []Package `json:"-"` // packages in this module
Sum string `json:"-"` // checksum for path, version (as in go.sum)
TestOnly bool `json:"-"` // is this module only required for tests?
Vendored bool `json:"-"` // is this a vendored module?
}
See https://golang.org/ref/mod#go-list-m
func FilterModules ¶ added in v1.0.0
func FilterModules(logger zerolog.Logger, moduleDir string, modules []Module, includeTest bool) ([]Module, error)
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 LoadModulesFromPackages ¶ added in v1.0.0
func LoadStdlibModule ¶ added in v1.1.0
LoadStdlibModule loads the standard library module.
func (Module) Coordinates ¶ added in v0.2.0
func (Module) PackageURL ¶
func (Module) ShortPackageURL ¶ added in v1.10.0
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(logger zerolog.Logger, 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
}
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