Documentation
¶
Index ¶
- Constants
- Variables
- func Each(dir string, f func(string) error) error
- func EachGomod(dir string, f func(string, *modfile.File) error) error
- func LoadEach(dir string, f func(string, []*packages.Package) error) error
- func LoadEachGomod(dir string, f func(string, *modfile.File, []*packages.Package) error) error
- type PackageLoadError
- type Walker
- func (w *Walker) Each(dir string, f func(string) error) error
- func (w *Walker) EachGomod(dir string, f func(string, *modfile.File) error) error
- func (w *Walker) LoadEach(dir string, f func(string, []*packages.Package) error) error
- func (w *Walker) LoadEachGomod(dir string, f func(string, *modfile.File, []*packages.Package) error) error
Constants ¶
const DefaultLoadMode = packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedTypesSizes | packages.NeedModule | packages.NeedEmbedFiles | packages.NeedEmbedPatterns
DefaultLoadMode is the default value for the Mode field of the packages.Config used by Walker.LoadEach and Walker.LoadEachGomod.
Variables ¶
var DefaultLoadConfig = packages.Config{Mode: DefaultLoadMode}
DefaultLoadConfig is the default value for the [Walker.LoadConfig] field used by Walker.LoadEach and Walker.LoadEachGomod.
Functions ¶
func Each ¶
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 ¶
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 ¶
LoadEach calls f once for each Go module in dir and its subdirectories, passing it the directory containing the go.mod file (which will have dir as a prefix) and a slice of packages.Package values loaded from that directory using the packages.Load function.
Types ¶
type PackageLoadError ¶
PackageLoadError is an error type that wraps an error that occurred while loading a package.
func (PackageLoadError) Error ¶
func (e PackageLoadError) Error() string
func (PackageLoadError) Unwrap ¶
func (e PackageLoadError) Unwrap() error
type Walker ¶
type Walker struct { // IncludeVendor controls whether to walk into vendor directories. IncludeVendor bool // IncludeTestdata controls whether to walk into testdata directories. IncludeTestdata bool // ParseLax controls whether to use [modfile.ParseLax] instead of [modfile.Parse]. ParseLax bool // Use [modfile.ParseLax] to parse go.mod files instead of [modfile.Parse]. // VersionFixer is a function that can be used to fix version strings in go.mod files. 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 [DefaultLoadMode] is used. // The Dir field of the config is set to the directory passed to [Walker.LoadEach] or [Walker.LoadEachGomod]. LoadConfig packages.Config // FailOnPackageErrors controls whether to return an error if any package fails to load. FailOnPackageErrors bool }
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 ¶
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 ¶
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 ¶
LoadEach calls f once for each Go module in dir and its subdirectories, passing it the directory containing the go.mod file (which will have dir as a prefix) and a slice of packages.Package values loaded from that directory using the packages.Load function. You can specify how loading is done by modifying w.LoadConfig. If w.LoadConfig is the zero value, a default value of DefaultLoadConfig is used. If w.LoadConfig is not the zero value but LoadConfig.Mode is zero, a default value of DefaultLoadMode is used.