Documentation ¶
Overview ¶
Package forklift provides a simple way to load Go packages.
There are three types of packages: normal packages, test packages, and external test packages. A normal package is the result of a "go build" command. A test package is the result of a "go test" command, excluding test files that declare a package name with a "_test" suffix. An external test package is the result of a "go test" command, excluding test files that do not declare a package name with a "_test" suffix.
To load the normal package in the current directory:
p, err := forklift.LoadPackage(".")
To load the test package in the "time" package:
p, err := forklift.LoadTestPackage("time")
To load the external test package in the "strings" package:
p, err := forklift.LoadExternalTestPackage("strings")
The result is a *golang.org/x/tools/go/packages.Package.
Paths are passed directly to golang.org/x/tools/go/packages.Load. All information is loaded.
To configure the loading behavior, use Loader.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultMode packages.LoadMode = packages.NeedCompiledGoFiles | packages.NeedDeps | packages.NeedEmbedFiles | packages.NeedEmbedPatterns | packages.NeedFiles | packages.NeedImports | packages.NeedModule | packages.NeedName | packages.NeedSyntax | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedTypesSizes
DefaultMode is the default Loader mode.
var ErrNotFound = fmt.Errorf("package not found")
ErrNotFound neans the package was not found.
Functions ¶
func LoadExternalTestPackage ¶
LoadExternalTestPackage returns the external test package for path. It returns ErrNotFound if the package is not found, and other errors.
func LoadPackage ¶
LoadPackage returns the package for path. It returns ErrNotFound if the package is not found, and other errors.
func LoadTestPackage ¶
LoadTestPackage returns the test package for path. It returns ErrNotFound if the package is not found, and other errors.
Types ¶
type Loader ¶
type Loader struct { // Context is used if set. Context context.Context // Dir is the build system working directory. It defaults to the current one. Dir string // Env is the build system environment variables. Env []string // Flags is the build system command-line flags. Flags []string // Mode is the information to include. Mode packages.LoadMode }
Loader provides Packages for import paths.
func (Loader) LoadExternalTestPackage ¶
LoadExternalTestPackage returns the external test package for path. It returns ErrNotFound if the package is not found, and other errors.
func (Loader) LoadPackage ¶
LoadPackage returns the package for path. It returns ErrNotFound if the package is not found, and other errors.
func (Loader) LoadTestPackage ¶
LoadTestPackage returns the test package for path. It returns ErrNotFound if the package is not found, and other errors.