packages

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	NeedName  = packages.NeedName
	NeedFiles = packages.NeedFiles

	NeedSyntax     = packages.NeedSyntax
	NeedImports    = packages.NeedImports
	NeedDeps       = packages.NeedDeps
	NeedModule     = packages.NeedModule
	NeedExportFile = packages.NeedExportFile

	NeedEmbedFiles      = packages.NeedEmbedFiles
	NeedEmbedPatterns   = packages.NeedEmbedPatterns
	NeedCompiledGoFiles = packages.NeedCompiledGoFiles

	NeedTypes      = packages.NeedTypes
	NeedTypesSizes = packages.NeedTypesSizes
	NeedTypesInfo  = packages.NeedTypesInfo

	NeedForTest = packages.NeedForTest
)
View Source
const (
	DebugPackagesLoad = false
)

Variables

This section is empty.

Functions

func Visit

func Visit(pkgs []*Package, pre func(*Package) bool, post func(*Package))

Visit visits all the packages in the import graph whose roots are pkgs, calling the optional pre function the first time each package is encountered (preorder), and the optional post function after a package's dependencies have been visited (postorder). The boolean result of pre(pkg) determines whether the imports of package pkg are visited.

Types

type Cached

type Cached struct {
	*packages.Package
	Types     *types.Package
	TypesInfo *types.Info
	Syntax    []*ast.File
}

type Config

type Config = packages.Config

A Config specifies details about how packages should be loaded. The zero value is a valid configuration. Calls to Load do not modify this struct.

type Deduper

type Deduper = *aDeduper

func NewDeduper

func NewDeduper() Deduper

func (Deduper) Check

func (p Deduper) Check(id string) *Cached

func (Deduper) SetLLGoFiles

func (p Deduper) SetLLGoFiles(files map[string][]string)

func (Deduper) SetPkgPath

func (p Deduper) SetPkgPath(fn func(path, name string) string)

func (Deduper) SetPreload

func (p Deduper) SetPreload(fn func(pkg *packages.Package))

func (Deduper) SetPrepare added in v1.0.5

func (p Deduper) SetPrepare(fn func([]*Package, *Config) error)

SetPrepare installs a graph preprocessing hook before parsing/type checking. The hook may add generated files and their imports (for example, coverage).

func (Deduper) SetRewrite added in v1.0.7

func (p Deduper) SetRewrite(fn func(*Package) (bool, error))

SetRewrite installs a typed source transformation. It runs after the initial check, before importing packages are checked. A changed package is checked again with fresh types and binding information; preload runs for that new package as well. The callback must add metadata for any injected imports.

type Error

type Error = packages.Error

type LoadMode

type LoadMode = packages.LoadMode

A LoadMode controls the amount of detail to return when loading. The bits below can be combined to specify which fields should be filled in the result packages. The zero value is a special case, equivalent to combining the NeedName, NeedFiles, and NeedCompiledGoFiles bits. ID and Errors (if present) will always be filled. Load may return more information than requested.

type Package

type Package = packages.Package

A Package describes a loaded Go package.

func LoadEx

func LoadEx(dedup Deduper, sizes func(sizes types.Sizes, compiler, arch string) types.Sizes, cfg *Config, patterns ...string) ([]*Package, error)

LoadEx loads and returns the Go packages named by the given patterns.

Config specifies loading options; nil behaves the same as an empty Config.

If any of the patterns was invalid as defined by the underlying build system, Load returns an error. It may return an empty list of packages without an error, for instance for an empty expansion of a valid wildcard. Errors associated with a particular package are recorded in the corresponding Package's Errors list, and do not cause Load to return an error. Clients may need to handle such errors before proceeding with further analysis. The PrintErrors function is provided for convenient display of all errors.

func LoadExWithGoVersion

func LoadExWithGoVersion(dedup Deduper, sizes func(sizes types.Sizes, compiler, arch string) types.Sizes, cfg *Config, goVersion string, patterns ...string) ([]*Package, error)

LoadExWithGoVersion is LoadEx with an optional go/types language version override. The version uses go/types syntax, such as "go1.22".

func LoadExWithSourceOverlay added in v1.0.7

func LoadExWithSourceOverlay(dedup Deduper, sizes func(sizes types.Sizes, compiler, arch string) types.Sizes, cfg *Config, goVersion string, sourceOverlay map[string][]byte, patterns ...string) ([]*Package, error)

LoadExWithSourceOverlay supplies an additional source view to LLGo's parser without changing the metadata driver's overlay. This lets a Go -overlay JSON select deleted and added files while native source patches and virtual files reach the parser without generating a conflicting go/packages overlay.

func LoadMetadata added in v1.0.7

func LoadMetadata(cfg *Config, patterns ...string) ([]*Package, error)

LoadMetadata runs the unmodified go/packages driver with the selected GOROOT/bin first on its process PATH. Setting Config.Env alone cannot do this: x/tools resolves exec.Command("go") using the process environment, including for GO111MODULE=off release-tag probes. The parent's environment is untouched. This loader is for metadata only; LoadEx supplies LLGo's parser and typechecker.

Jump to

Keyboard shortcuts

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