Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Api ¶
type Api interface { // Obtain the list of available generator names by looking for generator-*.yaml files in sourceBaseDir FindGeneratorNames(ctx context.Context, sourceBaseDir string) ([]string, error) // Obtain a specific generator spec, read from "generator-<generatorName>.yaml" in sourceBaseDir ObtainGeneratorSpec(ctx context.Context, sourceBaseDir string, generatorName string) (*GeneratorSpec, error) // Write a fresh RenderSpec with defaults set from the GeneratorSpec for the given generator // // The name of the output file can be set in request.RenderSpecFile, but if left empty, it defaults to // "generated-<generatorName>.yaml". // // Warning: if the file exists, it is silently overwritten! The idea is that you keep both your // generators and the generator targets in source control, so you can then review the changes made. WriteRenderSpecWithDefaults(ctx context.Context, request *Request, generatorName string) *Response // Write a RenderSpec file with the provided parameter values // // The name of the output file can be set in request.RenderSpecFile, but if left empty, it defaults to // "generated-<generatorName>.yaml". // // Warning: if the file exists, it is silently overwritten! The idea is that you keep both your // generators and the generator targets in source control, so you can then review the changes made. WriteRenderSpecWithValues(ctx context.Context, request *Request, generatorName string, parameters map[string]interface{}) *Response // Render files from templates according to RenderSpec and the GeneratorSpec it references. // // First the RenderSpec is read from <request.TargetBaseDir>/<request.RenderSpecFile>". // This tells the generator everything it needs to read the GeneratorSpec and execute it. // // If you leave request.RenderSpecFile empty, it defaults to "generated-main.yaml" // // Warning: existing files are silently overwritten! The idea is that you keep both your // generators and the generator targets in source control, so you can then review the changes made. Render(ctx context.Context, request *Request) *Response }
Functionality that this library exposes.
type FileResult ¶
type GeneratorSpec ¶
type GeneratorSpec struct { // The list of templates to render (if their condition evaluates to true) Templates []TemplateSpec `yaml:"templates"` // The list of available variables Variables map[string]VariableSpec `yaml:"variables"` }
Specifies what templates belong to a generator and what variables it needs to run.
Will be read from a generator-*.yaml file in the root directory of the generator.
The values of the variables as well as what generator to use come from a RenderSpec instead.
type RenderSpec ¶
type RenderSpec struct { // Name of the generator to use (determines yaml file to read for generator spec). The main one should be called // generator-main.yaml, and GeneratorName should be set to "main". GeneratorName string `yaml:"generator"` // Assign variable "key" value "value". All values are evaluated as templates until they no longer change, // so the value of one variable can refer to other variables, even if using their default values. Parameters map[string]interface{} `yaml:"parameters"` }
All Information needed by a render run.
The idea is that this is read from a generator-<name>.yaml file in the target directory so runs can be repeated.
You can also have this library render a file with the default values for a given generator.
type Request ¶
type Request struct { // Directory where to find e.g. 'main.yaml' describing the generator. Required. SourceBaseDir string `yaml:"sourcedir"` // Directory where to find 'generator-main.yaml' specifying values and the generator to use. Required. TargetBaseDir string `yaml:"targetdir"` // yaml-file to read for RenderSpec, if not set, defaults to "generated-main.yaml". RenderSpecFile string `yaml:"renderspec"` }
Parameters you will need to provide for a render run. All the rest is read from parameters
type Response ¶
type Response struct { Success bool RenderedFiles []FileResult Errors []error }
Information about the results of a render run
type TemplateSpec ¶
type TemplateSpec struct { RelativeSourcePath string `yaml:"source"` RelativeTargetPath string `yaml:"target"` Condition string `yaml:"condition"` WithItems []interface{} `yaml:"with_items"` WithFiles []string `yaml:"with_files"` JustCopy bool `yaml:"just_copy"` }
Specifies a template to process, or a list to iterate over, if WithItems is nonempty (setting {{ item }} each run)
Every field is evaluated as a template itself, so you can use variables in all fields.
If Condition is set and evaluates to one of 'false', '0', 'no', the render run is skipped
type VariableSpec ¶
type VariableSpec struct { // Human readable description for the variable. Description string `yaml:"description"` // Regex validation pattern that the string representation (%v) of the value must match. No validation if left empty. ValidationPattern string `yaml:"pattern"` // Default value. If missing, the variable is considered required. Note that variables can have structured content. DefaultValue interface{} `yaml:"default"` }
Specifies a variable that this generator uses, so it is made available in the templates.
Actual values for an invocation of the generator are set in a RenderSpec, not the GeneratorSpec.