autoimport

package module
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2019 License: MIT Imports: 13 Imported by: 2

README

autoimport

Godoc Report Tests Coverage Sponsor

A faster goimports implementation. It assumes that the files are part of a Go module and uses the information inside go.mod to find the import paths for external dependencies.

Installation

go get -u github.com/blitzprog/autoimport/...

CLI

autoimport hello.go world.go

Work in progress (currently API only, CLI is not available yet).

API

New
importer := autoimport.New("/home/user/projects/helloworld")

Creates a new importer inside the given project directory. The root directory must have a go.mod file. Otherwise it will traverse the directories going upwards until it finds a go.mod file.

Files
importer.Files([]string)

Work in progress. Automatically adds import statements to the given files.

Source
importer.Source([]byte)

Work in progress.

Style

Please take a look at the style guidelines if you'd like to make a pull request.

Sponsors

Cedric Fung Scott Rayapoullé Eduard Urbach
Cedric Fung Scott Rayapoullé Eduard Urbach

Want to see your own name here?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoImport

type AutoImport struct {
	// contains filtered or unexported fields
}

AutoImport helps you automatically add imports to your source files.

func New

func New(moduleDirectory string) *AutoImport

New creates a new auto import.

func (*AutoImport) Imports

func (importer *AutoImport) Imports(src []byte) ([]string, error)

Imports returns the import paths used in the given source file.

func (*AutoImport) Source

func (importer *AutoImport) Source(src []byte) ([]byte, error)

Source finds the correct import statements and returns code that includes import paths.

type Dependency

type Dependency struct {
	ImportPath string
	Version    string
}

Dependency represents a single package dependency in a go.mod file.

type Package

type Package struct {
	Name          string // Actual package name as declared by the package keyword
	RealPath      string // Real file path
	ImportPath    string // Import path used in Go source files
	DirectoryName string // Base name of the directory
	IsModuleRoot  bool   // Only root packages have go.mod files
}

Package represents a single Go package.

type PackageIndex

type PackageIndex = map[string][]*Package

PackageIndex is a map that maps a package name to possible import paths.

func GetPackagesInDirectory added in v0.4.0

func GetPackagesInDirectory(scanPath string, importPathPrefix string) PackageIndex

GetPackagesInDirectory returns a map of package names mapped to packages.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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