Documentation ¶
Overview ¶
Astmod is a Go AST manipulation library to rewrite import statement in the AST (in-place). It also allows listing the imports matching the given prefix.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListImportPaths ¶
ListImportPaths returns a slice of strings for the unique imports paths matching the given prefix.
func Rewrite ¶
func Rewrite(fname string, src interface{}, fromPrefix, toPrefix string) (buf *bytes.Buffer, err error)
Rewrite modifies the AST to rewrite import statements. src should be compatible with go/parser/#ParseFile: (The type of the argument for the src parameter must be string, []byte, or io.Reader.)
return of nil, nil (no result, no error) means no changes are needed
Types ¶
type ImportSpec ¶
type ImportSpec struct {
Name, Path string
}
ImportSpec is a slimmed-down version of https://golang.org/pkg/go/ast/#ImportSpec.
func ListImports ¶
func ListImports(fname string, src interface{}, prefix string) ([]*ImportSpec, error)
ListImports returns a set of ImportSpec objects with imports matching the given prefix.
func (*ImportSpec) String ¶
func (i *ImportSpec) String() string
String prints the import with the name field prepended (if not empty).