Documentation ¶
Index ¶
- func Apply(inputPath string, transformations []FileTransformation) error
- func WriteGoFile(path string, reader io.Reader) error
- func WriteGoTemplate(path string, tmpl *template.Template, value interface{}) error
- func WriteTemplate(path string, tmpl *template.Template, value interface{}) error
- type FileContext
- type FileTransformation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(inputPath string, transformations []FileTransformation) error
Apply recursively walks the file-system, starting at the given input path, and applies the given transformations to all go-files encountered on the way. For each file, the transformations are executed in the order that they have in the array.
func WriteGoFile ¶
WriteGoFile writes the contents of a reader to the given path, formatting it and running go imports on the output.
func WriteGoTemplate ¶
WriteGoTemplate applies the given template to the value and writes it out as a Go file, formatting it and running go imports on it.
Types ¶
type FileContext ¶
FileContext contains all the data that is passed down to every call to Apply of a FileTransformation.
type FileTransformation ¶
type FileTransformation interface { // Prepare is called before any processing takes place. Prepare() error // Apply is where the action happens; called once for every file. Apply(FileContext) error // Finalize is called once all files have been visited. Use this to write out // summaries that depend on all files. Finalize() error }
FileTransformation represents a general kind of in-place transformation that is applied file-wise. It doesn't have to do anything to the files themselves; it might just as well simply collect information etc.
func AddImport ¶
func AddImport(path string) FileTransformation
AddImport adds an import to a file, if it is not already present.
func AddNamedImport ¶
func AddNamedImport(name, path string) FileTransformation
AddNamedImport adds a named import to a file, if it is not already present.
func ChangePackageName ¶
func ChangePackageName(name string) FileTransformation
ChangePackageName changes the name of the package in a file.
func DropBuildIgnore ¶
func DropBuildIgnore() FileTransformation
DropBuildIgnore removes // +build ignore comments from a file.
func RemoveImport ¶
func RemoveImport(path string) FileTransformation