// Find returns the name of an object (.o) or archive (.a) file // containing type information for the specified import path, // using the go command. // If no file was found, an empty filename is returned. // // A relative srcDir is interpreted relative to the current working directory. // // Find also returns the package's resolved (canonical) import path, // reflecting the effects of srcDir and vendoring on importPath. // // Deprecated: Use the higher-level API in golang.org/x/tools/go/packages, // which is more efficient. func Find(importPath, srcDir string) (filename, path string) { … } // NewReader returns a reader for the export data section of an object // (.o) or archive (.a) file read from r. The new reader may provide // additional trailing data beyond the end of the export data. func NewReader(r io.Reader) (io.Reader, error) { … } // readAll works the same way as io.ReadAll, but avoids allocations and copies // by preallocating a byte slice of the necessary size if the size is known up // front. This is always possible when the input is an archive. In that case, // NewReader will return the known size using an io.LimitedReader. func readAll(r io.Reader) ([]byte, error) { … } // Read reads export data from in, decodes it, and returns type // information for the package. // // The package path (effectively its linker symbol prefix) is // specified by path, since unlike the package name, this information // may not be recorded in the export data. // // File position information is added to fset. // // Read may inspect and add to the imports map to ensure that references // within the export data to other packages are consistent. The caller // must ensure that imports[path] does not exist, or exists but is // incomplete (see types.Package.Complete), and Read inserts the // resulting package into this map entry. // // On return, the state of the reader is undefined. func Read(in io.Reader, fset *token.FileSet, imports map[string]*types.Package, path string) (*types.Package, error) { … } // Write writes encoded type information for the specified package to out. // The FileSet provides file position information for named objects. func Write(out io.Writer, fset *token.FileSet, pkg *types.Package) error { … } // ReadBundle reads an export bundle from in, decodes it, and returns type // information for the packages. // File position information is added to fset. // // ReadBundle may inspect and add to the imports map to ensure that references // within the export bundle to other packages are consistent. // // On return, the state of the reader is undefined. // // Experimental: This API is experimental and may change in the future. func ReadBundle(in io.Reader, fset *token.FileSet, imports map[string]*types.Package) ([]*types.Package, error) { … } // WriteBundle writes encoded type information for the specified packages to out. // The FileSet provides file position information for named objects. // // Experimental: This API is experimental and may change in the future. func WriteBundle(out io.Writer, fset *token.FileSet, pkgs []*types.Package) error { … }