gomod

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const StdlibModulePath = "std"

StdlibModulePath defines the path used for Go's standard library module.

Variables

View Source
var ErrNoModule = errors.New("not a go module")

ErrNoModule indicates that a given path is not a valid Go module

View Source
var ErrNotVendoring = errors.New("the module is not vendoring its dependencies")

Functions

func ApplyModuleGraph added in v1.0.0

func ApplyModuleGraph(logger zerolog.Logger, moduleDir string, modules []Module) error

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

func GetModuleVersion(logger zerolog.Logger, moduleDir string) (string, error)

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

func GetVersionFromTag(logger zerolog.Logger, moduleDir string) (string, error)

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 IsModule added in v1.0.0

func IsModule(dir string) bool

IsModule determines whether dir is a Go module.

func IsVendoring added in v1.0.0

func IsVendoring(moduleDir string) bool

IsVendoring determines whether of not the module at moduleDir is vendoring its dependencies.

func ResolveLocalReplacements added in v1.0.0

func ResolveLocalReplacements(logger zerolog.Logger, mainModuleDir string, modules []Module) error

ResolveLocalReplacements tries to resolve paths and versions for local replacement modules.

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

func LoadBuildInfo(binaryPath string) (*BuildInfo, error)

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 GetVendoredModules(logger zerolog.Logger, moduleDir string, includeTest bool) ([]Module, error)

func LoadModule added in v1.0.0

func LoadModule(logger zerolog.Logger, moduleDir string) (*Module, error)

func LoadModules added in v1.0.0

func LoadModules(logger zerolog.Logger, moduleDir string, includeTest bool) ([]Module, error)

func LoadModulesFromPackages added in v1.0.0

func LoadModulesFromPackages(logger zerolog.Logger, moduleDir, packagePattern string) ([]Module, error)

func LoadStdlibModule added in v1.1.0

func LoadStdlibModule(logger zerolog.Logger) (*Module, error)

LoadStdlibModule loads the standard library module.

func (Module) BOMRef added in v1.4.0

func (m Module) BOMRef() string

func (Module) Coordinates added in v0.2.0

func (m Module) Coordinates() string

func (Module) Hash added in v0.3.0

func (m Module) Hash() (string, error)

func (Module) PackageURL

func (m Module) PackageURL() string

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
}

See https://golang.org/cmd/go/#hdr-List_packages_or_modules

func LoadPackage added in v1.0.0

func LoadPackage(logger zerolog.Logger, moduleDir, packagePattern string) (*Package, error)

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

Jump to

Keyboard shortcuts

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