Documentation ¶
Index ¶
- Variables
- func PackageAST(path string) (pkg *ast.Package, err error)
- func PackageTestAST(path string) (pkg *ast.Package, err error)
- type FileFilter
- type FileFilters
- type FileType
- type GoPath
- type Importer
- func (i *Importer) GetSourceFiles(path, srcDir string, filters FileFilters) (string, []string, error)
- func (i *Importer) Import(path string) (*types.Package, error)
- func (i *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error)
- func (i *Importer) ImportFromWithFilters(path, srcDir string, mode types.ImportMode, filters FileFilters) (*types.Package, error)
- func (i *Importer) ImportWithFilters(path string, filters FileFilters) (*types.Package, error)
- func (i *Importer) ParseSourceFiles(root string, paths []string) (*types.Package, error)
Constants ¶
This section is empty.
Variables ¶
DefaultGoPath contains the default list of go paths provided either via GOPATH environment variable or the default value.
var ErrNotInGoPath = fmt.Errorf("parseutil: package is not in any of the go paths")
ErrNotInGoPath is an error returned when a package is not in any of the possible go paths.
var ErrTooManyPackages = errors.New("more than one package found in a directory")
ErrTooManyPackages is returned when there is more than one package in a directory where there should only be one Go package.
Functions ¶
func PackageAST ¶
PackageAST returns the AST of the package at the given path.
Types ¶
type FileFilter ¶
FileFilter returns true if the given file needs to be kept.
type FileFilters ¶
type FileFilters []FileFilter
FileFilters represents a colection of FileFilter
type GoPath ¶ added in v1.1.2
type GoPath []string
GoPath is the collection of all go paths.
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
Importer is an implementation of `types.Importer` and `types.ImporterFrom` that builds actual source files and not the compiled objects in the pkg directory. It is safe to use it concurrently. A package is cached after building it the first time.
func NewImporter ¶
func NewImporter() *Importer
NewImporter creates a new Importer instance with the default importer of the runtime assigned as the underlying importer.
func (*Importer) GetSourceFiles ¶ added in v1.1.1
func (i *Importer) GetSourceFiles(path, srcDir string, filters FileFilters) (string, []string, error)
GetSourceFiles return the go files available in src under path after applying the filters.
func (*Importer) Import ¶
Import returns the imported package for the given import path, or an error if the package couldn't be imported. Two calls to Import with the same path return the same package.
func (*Importer) ImportFrom ¶
ImportFrom returns the imported package for the given import path when imported by the package in srcDir, or an error if the package couldn't be imported. The mode value must be 0; it is reserved for future use. Two calls to ImportFrom with the same path and srcDir return the same package.
func (*Importer) ImportFromWithFilters ¶
func (i *Importer) ImportFromWithFilters(path, srcDir string, mode types.ImportMode, filters FileFilters) (*types.Package, error)
ImportFromWithFilters works like ImportFrom but filters the source files using the passed FileFilters.
func (*Importer) ImportWithFilters ¶
ImportWithFilters works like Import but filtering the source files to parse using the passed FileFilters.