Documentation
¶
Overview ¶
Package templates allows processing multiple templates which use common data
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTemplateExecution is returned when template.Execute method fails ErrTemplateExecution = errors.New("executing template") // ErrSavingFiles is returned when an issue with processing templates occurs ErrSavingFiles = errors.New("saving processed terraform file") // ErrNoFile is returned when there is no template file ErrNoFile = errors.New("no template file") )
Functions ¶
This section is empty.
Types ¶
type DataForTarget ¶
DataForTarget holds data about (template) output file to input data that this template needs
func (DataForTarget) Join ¶
func (d DataForTarget) Join(toAdd DataForTarget) DataForTarget
Join merges two DataForTargets
type FSMultiTargetProcessor ¶
FSMultiTargetProcessor allows to work on templates that are stored as fs.FS as implementation of MultiTargetProcessor interface
func (FSMultiTargetProcessor) ProcessTemplates ¶
func (t FSMultiTargetProcessor) ProcessTemplates(data MultiTargetData, filterFuncs ...func([]string) ([]string, error)) error
ProcessTemplates searches for templates inside fs.FS. Later it executes for each template, for each target (and its data) that is provided in input.
type FSTemplateProcessor ¶
type FSTemplateProcessor struct { TemplatesFS fs.FS TemplateTargets map[string]string AdditionalFuncs template.FuncMap }
FSTemplateProcessor allows working with templates stored as fs.FS it contains the fs.FS as source of templates as well as a map which stores template names with target files to which the result should be written All templates within TemplatesFS should have .tmpl extension AdditionalFuncs can be used to add custom template functions
func (FSTemplateProcessor) AddTemplateTarget ¶
func (t FSTemplateProcessor) AddTemplateTarget(templateName, targetPath string)
AddTemplateTarget provides ability to specify additional template target after the processor was created
func (FSTemplateProcessor) ProcessTemplates ¶
func (t FSTemplateProcessor) ProcessTemplates(data interface{}, filterFuncs ...func([]string) ([]string, error)) error
ProcessTemplates parses templates located in fs.FS and executes them using the provided data result of each template execution is persisted in location provided in FSTemplateProcessor.TemplateTargets
func (FSTemplateProcessor) TemplateExists ¶
func (t FSTemplateProcessor) TemplateExists(fileName string) bool
TemplateExists returns information if given template exists
type MockMultiTargetProcessor ¶
MockMultiTargetProcessor is a mock for MultiTargetProcessor
func (*MockMultiTargetProcessor) ProcessTemplates ¶
func (m *MockMultiTargetProcessor) ProcessTemplates(i MultiTargetData, filterFuncs ...func([]string) ([]string, error)) error
ProcessTemplates is a mocked version
type MockProcessor ¶
MockProcessor is a mock for TemplateProcessor
func (*MockProcessor) AddTemplateTarget ¶
func (m *MockProcessor) AddTemplateTarget(templateName, targetPath string)
AddTemplateTarget is a mocked version
func (*MockProcessor) ProcessTemplates ¶
func (m *MockProcessor) ProcessTemplates(i interface{}, filterFuncs ...func([]string) ([]string, error)) error
ProcessTemplates is a mocked version
func (*MockProcessor) TemplateExists ¶
func (m *MockProcessor) TemplateExists(fileName string) bool
TemplateExists is a mocked version
type MultiTargetData ¶
type MultiTargetData map[string]DataForTarget
MultiTargetData holds relationship between template to be executed and map of entries for which this template is to be executed
func (MultiTargetData) AddData ¶
func (m MultiTargetData) AddData(templateTarget string, toAdd DataForTarget) MultiTargetData
AddData adds data for processing for a template. If the template already exists, it merges data.
type MultiTargetProcessor ¶
type MultiTargetProcessor interface { // ProcessTemplates processes template ProcessTemplates(MultiTargetData, ...func([]string) ([]string, error)) error }
MultiTargetProcessor allows processing multiple templates that each template and each target uses different data
type TemplateProcessor ¶
type TemplateProcessor interface { // ProcessTemplates is used to parse given template/templates using the given data as input // If template execution fails, ProcessTemplates should return ErrTemplateExecution ProcessTemplates(interface{}, ...func([]string) ([]string, error)) error // AddTemplateTarget provides ability to specify additional template target after the processor was created AddTemplateTarget(string, string) // TemplateExists returns information if given template exists TemplateExists(string) bool }
TemplateProcessor allows processing multiple templates which use common data