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 LoadMode = packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedTypesSizes | packages.NeedModule | packages.NeedEmbedFiles | packages.NeedEmbedPatterns
Variables ¶
var DefaultLoadConfig = packages.Config{Mode: LoadMode}
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.
Types ¶
type PackageLoadError ¶
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 ¶
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.