https://github.com/willfaught/forklift
A simple way to load Go packages
https://github.com/willfaught/forklift
go loader package
Last synced: about 1 year ago
JSON representation
A simple way to load Go packages
- Host: GitHub
- URL: https://github.com/willfaught/forklift
- Owner: willfaught
- License: mit
- Created: 2023-07-08T22:17:35.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-20T20:21:13.000Z (about 2 years ago)
- Last Synced: 2025-04-01T15:18:49.168Z (about 1 year ago)
- Topics: go, loader, package
- Language: Go
- Homepage: https://pkg.go.dev/github.com/willfaught/forklift
- Size: 23.4 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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](https://pkg.go.dev/golang.org/x/tools/go/packages#Package).
Paths are passed directly to [golang.org/x/tools/go/packages.Load](https://pkg.go.dev/golang.org/x/tools/go/packages#Load). All information is loaded.
To configure the loading behavior, use [Loader](https://pkg.go.dev/github.com/willfaught/forklift#Loader).