type LoadMode … const NeedName … const NeedFiles … const NeedCompiledGoFiles … const NeedImports … const NeedDeps … const NeedExportFile … const NeedTypes … const NeedSyntax … const NeedTypesInfo … const NeedTypesSizes … const needInternalDepsErrors … const needInternalForTest … const typecheckCgo … const NeedModule … const NeedEmbedFiles … const NeedEmbedPatterns … const LoadFiles … const LoadImports … const LoadTypes … const LoadSyntax … const LoadAllSyntax … const NeedExportsFile … type Config … // Load loads and returns the Go packages named by the given patterns. // // The cfg parameter specifies loading options; nil behaves the same as an empty [Config]. // // The [Config.Mode] field is a set of bits that determine what kinds // of information should be computed and returned. Modes that require // more information tend to be slower. See [LoadMode] for details // and important caveats. Its zero value is equivalent to // [NeedName] | [NeedFiles] | [NeedCompiledGoFiles]. // // Each call to Load returns a new set of [Package] instances. // The Packages and their Imports form a directed acyclic graph. // // If the [NeedTypes] mode flag was set, each call to Load uses a new // [types.Importer], so [types.Object] and [types.Type] values from // different calls to Load must not be mixed as they will have // inconsistent notions of type identity. // // 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 Load(cfg *Config, patterns ...string) ([]*Package, error) { … } // defaultDriver is a driver that implements go/packages' fallback behavior. // It will try to request to an external driver, if one exists. If there's // no external driver, or the driver returns a response with NotHandled set, // defaultDriver will fall back to the go list driver. // The boolean result indicates that an external driver handled the request. func defaultDriver(cfg *Config, patterns ...string) (*DriverResponse, bool, error) { … } // splitIntoChunks chunks the slice so that the total number of characters // in a chunk is no longer than argMax. func splitIntoChunks(patterns []string, argMax int) ([][]string, error) { … } func callDriverOnChunks(driver driver, cfg *Config, chunks [][]string) (*DriverResponse, error) { … } func mergeResponses(responses ...*DriverResponse) *DriverResponse { … } type Package … type Module … type ModuleError … func init() { … } type Error … type ErrorKind … const UnknownError … const ListError … const ParseError … const TypeError … func (err Error) Error() string { … } type flatPackage … // MarshalJSON returns the Package in its JSON form. // For the most part, the structure fields are written out unmodified, and // the type and syntax fields are skipped. // The imports are written out as just a map of path to package id. // The errors are written using a custom type that tries to preserve the // structure of error types we know about. // // This method exists to enable support for additional build systems. It is // not intended for use by clients of the API and we may change the format. func (p *Package) MarshalJSON() ([]byte, error) { … } // UnmarshalJSON reads in a Package from its JSON format. // See MarshalJSON for details about the format accepted. func (p *Package) UnmarshalJSON(b []byte) error { … } func (p *Package) String() string { … } type loaderPackage … type loader … type parseValue … func newLoader(cfg *Config) *loader { … } // refine connects the supplied packages into a graph and then adds type // and syntax information as requested by the LoadMode. func (ld *loader) refine(response *DriverResponse) ([]*Package, error) { … } // loadRecursive loads the specified package and its dependencies, // recursively, in parallel, in topological order. // It is atomic and idempotent. // Precondition: ld.Mode&NeedTypes. func (ld *loader) loadRecursive(lpkg *loaderPackage) { … } // loadPackage loads the specified package. // It must be called only once per Package, // after immediate dependencies are loaded. // Precondition: ld.Mode & NeedTypes. func (ld *loader) loadPackage(lpkg *loaderPackage) { … } type importerFunc … func (f importerFunc) Import(path string) (*types.Package, error) { … } var ioLimit … func (ld *loader) parseFile(filename string) (*ast.File, error) { … } // parseFiles reads and parses the Go source files and returns the ASTs // of the ones that could be at least partially parsed, along with a // list of I/O and parse errors encountered. // // Because files are scanned in parallel, the token.Pos // positions of the resulting ast.Files are not ordered. func (ld *loader) parseFiles(filenames []string) ([]*ast.File, []error) { … } // sameFile returns true if x and y have the same basename and denote // the same file. func sameFile(x, y string) bool { … } // loadFromExportData ensures that type information is present for the specified // package, loading it from an export data file on the first request. // On success it sets lpkg.Types to a new Package. func (ld *loader) loadFromExportData(lpkg *loaderPackage) error { … } // impliedLoadMode returns loadMode with its dependencies. func impliedLoadMode(loadMode LoadMode) LoadMode { … } func usesExportData(cfg *Config) bool { … } var _ …