Documentation ¶
Overview ¶
Package generation is used for generation and saving files. For example, handlers, routes, etc.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Type ¶
type Type struct { // Path is a directory where generated file will be stored. // Example: ./assets/routes/ // It is expected to be relative to the root of a project. Path string // Package is a name of a generated file without extension. // It may be used as a package name in case of generating go files. Package string // Extension is added to the end of name of a generated file. // So file will be saved to: // filepath.Join(Path, Package+Extension) Extension string // Name of the template that is used by this Type. TemplateName string // Template is a skeleton of file that has to be generated. Template *template.Template // Context is used for passing data to the Template. Context map[string]interface{} }
Type is a context that stores information that is used for generation and saving files (mostly go packages).
func NewType ¶
NewType reads the requested template and returns an output.Type with initialized Template field. << and >> are used as delimiters. "\" + "\n" sequences are removed from the template so newline elision is supported. Moreover, ":" + "\t" are removed too for a possibility of a better code formatting.
func (*Type) CreateDir ¶
CreateDir initializes output.Type.Path with the requested path and tries to create it in filesystem if it doesn't exist yet. It panics in case of error.
func (*Type) Generate ¶
func (t *Type) Generate()
Generate creates a file with a name specified in Type.Package and Type.Extension in the location defined in Type.Path and with the content defined by Type.Template. The output directory should be created in advance. It's possible to do it using:
CreateDir("./path/to/output/")