forklift

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 5 Imported by: 2

README

forklift

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.

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

DefaultMode is the default Loader mode.

View Source
var ErrNotFound = fmt.Errorf("package not found")

ErrNotFound neans the package was not found.

Functions

func LoadExternalTestPackage

func LoadExternalTestPackage(path string) (*packages.Package, error)

LoadExternalTestPackage returns the external test package for path. It returns ErrNotFound if the package is not found, and other errors.

func LoadPackage

func LoadPackage(path string) (*packages.Package, error)

LoadPackage returns the package for path. It returns ErrNotFound if the package is not found, and other errors.

func LoadTestPackage

func LoadTestPackage(path string) (*packages.Package, error)

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

func (l Loader) LoadExternalTestPackage(path string) (*packages.Package, error)

LoadExternalTestPackage returns the external test package for path. It returns ErrNotFound if the package is not found, and other errors.

func (Loader) LoadPackage

func (l Loader) LoadPackage(path string) (*packages.Package, error)

LoadPackage returns the package for path. It returns ErrNotFound if the package is not found, and other errors.

func (Loader) LoadTestPackage

func (l Loader) LoadTestPackage(path string) (*packages.Package, error)

LoadTestPackage returns the test package for path. It returns ErrNotFound if the package is not found, and other errors.

Jump to

Keyboard shortcuts

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