Templates are the implementation for your generator. They are parameterized files which are filled in with data from the schema.
- Based on Go
text/templatewith extra helpers
- Support for partial templates for reuse and separate of concerns
- Typically in files, can also be a string in your CUE
Generators have several kinds of files that end up in the output
- Once Templates - used to generate a single file, like
- Repeated Templates - used in a loop to generate files per entry, for routes in this example
- Partial Templates - code snippets which are available in other templates
- Static Files - copied directly into the output, bypassing the template engine
These files are needed once for every server we generate.
Some have minimal templating and others loop over values, like
Repeated and Partial Templates
We separate the handler into a template which uses the partial. This is for demonstration purpose here and will be more useful in the “full-example” section where the implementation is more complete.
Rendered Output Files
Here we can see the result of code generation for a sample of the files. We will actually generate these in the next section. They are provided here so you can see the input / output pairs on a single page.