goImports

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoImports

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

GoImports holds information about the host package and the imports that exist inside it

func New

func New(packagePath string) *GoImports

New will create a new import list to a GO file/package

Note that the packagePath param is the path to the host package, and will be used to calculate the other imports

func (*GoImports) AddImport

func (i *GoImports) AddImport(suggestedAlias, packagePath string) string

AddImport will take some alias and package path and try to add it to the list of imports

The given alias is just a suggestion, it can be changed if there's a clash with another import alias

If the package path is already inside the import list, it's alias will be returned

func (*GoImports) AliasFromPath

func (i *GoImports) AliasFromPath(packagePath string) string

AliasFromPath will take some package path as argument and return the alias associated with it

Note that if, and only if, there's no package with the given path in the import list, the returned alias will be empty

func (*GoImports) MergeImports

func (i *GoImports) MergeImports(other *GoImports) map[string]string

MergeImports will merge the given imports list with the method receiver *GoImports

When merging, some aliases maybe change due to clashes. All renamed aliases will be returned in a map of oldAlias -> newAlias

func (*GoImports) NeedImport

func (i *GoImports) NeedImport(otherPackagePath string) bool

NeedImport will return true if the given package path needs to be imported, when called inside the import list host package

func (*GoImports) PackagePath

func (i *GoImports) PackagePath() string

PackagePath returns the path to the host package

func (*GoImports) SourceCode

func (i *GoImports) SourceCode() string

SourceCode will transform the list of imports in valid GO source code, ready to be compiled

Jump to

Keyboard shortcuts

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