importer

package
v0.0.5-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package importer provides a function to parse a directory and returns the package information

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAtleastOnePackageRequired = fmt.Errorf("expected atleast one package")
	ErrIncorrectPackageAmount    = fmt.Errorf("unexpected amount of packages")
	ErrUnableToFindIdentifier    = fmt.Errorf("unable to find identifier")
)

error definitions

Functions

func FileFilter

func FileFilter(fileInfo os.FileInfo) bool

FileFilter filter files which should not be included in this case all files which end with _test.go

func GetImportSpecForIdentifierAndFile

func GetImportSpecForIdentifierAndFile(identifier string, file *ast.File) (*ast.ImportSpec, error)

GetImportSpecForIdentifierAndFile Find an import spec for given identifier in given file

func ImportPathToFilePath

func ImportPathToFilePath(i *ast.ImportSpec) (string, error)

ImportPathToFilePath converts an import path to file path

func TryToFindIdentifier

func TryToFindIdentifier(identifier string, file *ast.File) (*ast.ImportSpec, error)

TryToFindIdentifier in case this is hit, we got unresolved imports an example could be "somepkg/v2"

Types

type PackageInfo

type PackageInfo struct {
	RootDir string
	RootPkg string

	PkgInfo map[string]map[string]*ast.Package
}

PackageInfo package info contains information about a package defined in a directory

func ParseRoot

func ParseRoot(dir string) (*PackageInfo, error)

ParseRoot parse a root directory

func (*PackageInfo) FileForPointer

func (p *PackageInfo) FileForPointer(pointer *PkgResolverPointer) *ast.File

FileForPointer retrieve ast file for pointer

func (*PackageInfo) FindImport

func (p *PackageInfo) FindImport(pointer *PkgResolverPointer, selector, identifier string) (bool, ast.Expr, *PkgResolverPointer)

FindImport finds a imported object on selector and identifier

func (*PackageInfo) FindInCurrent

func (p *PackageInfo) FindInCurrent(pointer *PkgResolverPointer, identifier string) (bool, ast.Expr, *PkgResolverPointer)

FindInCurrent tries to find an indentifier in current package

func (*PackageInfo) GetRootPkg

func (p *PackageInfo) GetRootPkg() map[string]*ast.File

GetRootPkg retrieve the root package

func (*PackageInfo) IsRoot

func (p *PackageInfo) IsRoot(pointer *PkgResolverPointer) bool

IsRoot check if pointer is in root some decisions need to be based on this

func (*PackageInfo) PkgForPointer

func (p *PackageInfo) PkgForPointer(pointer *PkgResolverPointer) *ast.Package

PkgForPointer retrieve ast package for pointer

func (*PackageInfo) PkgsForDir

func (p *PackageInfo) PkgsForDir(dir string) map[string]*ast.Package

PkgsForDir resolve directory

type PkgResolverPointer

type PkgResolverPointer struct {
	Dir  string
	Pkg  string
	File string
}

PkgResolverPointer pointer of a the package resolver used to identify where to look for specific values

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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