modules

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

Variables

View Source
var DefaultLoadConfig = packages.Config{Mode: LoadMode}

Functions

func Each

func Each(dir string, f func(string) error) error

Each calls f for each Go module in dir and its subdirectories. A Go module is identified by the presence of a go.mod file. The argument to f is the directory containing the go.mod file, which will have dir as a prefix. This function calls Walker.Each with a default Walker.

func EachGomod

func EachGomod(dir string, f func(string, *modfile.File) error) error

EachGomod calls f for each Go module in dir and its subdirectories. A Go module is identified by the presence of a go.mod file. The arguments to f are the directory containing the go.mod file (which will have dir as a prefix) and the parsed go.mod file. This function calls Walker.EachGomod with a default Walker.

func LoadEach

func LoadEach(dir string, f func(string, []*packages.Package) error) error

func LoadEachGomod

func LoadEachGomod(dir string, f func(string, *modfile.File, []*packages.Package) error) error

LoadEachGomod combines LoadEach and EachGomod.

Types

type PackageLoadError

type PackageLoadError struct {
	PkgPath string
	Err     error
}

func (PackageLoadError) Error

func (e PackageLoadError) Error() string

func (PackageLoadError) Unwrap

func (e PackageLoadError) Unwrap() error

type Walker

type Walker struct {
	IncludeVendor   bool // If true, walk into vendor directories. If false, skip them.
	IncludeTestdata bool // If true, walk into testdata directories. If false, skip them.

	ParseLax     bool                 // Use [modfile.ParseLax] to parse go.mod files instead of [modfile.Parse].
	VersionFixer modfile.VersionFixer // Use this version-string fixing function when parsing go.mod files.

	// This is the config to pass to [packages.Load]
	// when loading packages in [Walker.LoadEach] and [Walker.LoadEachGomod].
	// If this is the zero config,
	// a default value of [DefaultLoadConfig] is used.
	// If this is not the zero config but LoadConfig.Mode is zero,
	// a default value of [LoadMode] is used.
	// The Dir field of the config is set to the directory passed to [Walker.LoadEach] or [Walker.LoadEachGomod].
	LoadConfig          packages.Config
	FailOnPackageErrors bool // If true, return an error if any package fails to load.
}

Walker is a controller for various methods that walk a directory tree of Go modules. The zero value is a valid walker.

func (*Walker) Each

func (w *Walker) Each(dir string, f func(string) error) error

Each calls f for each Go module in dir and its subdirectories. A Go module is identified by the presence of a go.mod file. The arguments to f is the directory containing the go.mod file, which will have dir as a prefix.

func (*Walker) EachGomod

func (w *Walker) EachGomod(dir string, f func(string, *modfile.File) error) error

EachGomod calls f for each Go module in dir and its subdirectories. A Go module is identified by the presence of a go.mod file. The arguments to f are the directory containing the go.mod file (which will have dir as a prefix) and the parsed go.mod file.

func (*Walker) LoadEach

func (w *Walker) LoadEach(dir string, f func(string, []*packages.Package) error) error

func (*Walker) LoadEachGomod

func (w *Walker) LoadEachGomod(dir string, f func(string, *modfile.File, []*packages.Package) error) error

LoadEachGomod combines LoadEach and EachGomod.

Jump to

Keyboard shortcuts

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