Documentation
¶
Index ¶
- type GoImports
- func (i *GoImports) AddImport(suggestedAlias, packagePath string) string
- func (i *GoImports) AliasFromPath(packagePath string) string
- func (i *GoImports) MergeImports(other *GoImports) map[string]string
- func (i *GoImports) NeedImport(otherPackagePath string) bool
- func (i *GoImports) PackagePath() string
- func (i *GoImports) SourceCode() string
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
NeedImport will return true if the given package path needs to be imported, when called inside the import list host package
func (*GoImports) PackagePath ¶
PackagePath returns the path to the host package
func (*GoImports) SourceCode ¶
SourceCode will transform the list of imports in valid GO source code, ready to be compiled