Documentation
¶
Overview ¶
Package gofiles provides functions for specifying and writing Go source files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Write ¶
func Write(dir string, files []GoFileSpec) (map[string]GoFile, error)
Write the Go files represented by the specifications in the files parameter using the provided directory as the root directory. The Src field of each file is run as a Go template provided with the output of the "imports" function. This allows source files to import other files being written as part of the operation. For example:
"{{index . "bar/bar.go"}}" // resolves to the import path for the spec with RelPath "bar/bar.go"
Returns a map of the written files where the key is the RelPath field of the specification that was written and the value is the GoFile that was written for the specification.
Types ¶
type GoFile ¶
type GoFile struct {
// The absolute path to the Go file.
Path string
// The import path for the Go file. For example, "github.com/nmiyake/pkg/gofiles".
ImportPath string
}
GoFile represents a Go file that has been written to disk.
type GoFileSpec ¶
type GoFileSpec struct {
// The relative path to which the file should be written. For example, "foo/foo.go".
RelPath string
// Content of the file.
Src string
}
GoFileSpec represents the specification for a Go file.