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 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 ¶ added in v1.4.0
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 ¶ added in v1.4.0
func (t FSTemplateProcessor) TemplateExists(fileName string) bool
TemplateExists returns information if given template exists
type MockProcessor ¶ added in v1.4.0
MockProcessor is a mock for TemplateProcessor
func (*MockProcessor) AddTemplateTarget ¶ added in v1.4.0
func (m *MockProcessor) AddTemplateTarget(templateName, targetPath string)
AddTemplateTarget is a mocked version
func (*MockProcessor) ProcessTemplates ¶ added in v1.4.0
func (m *MockProcessor) ProcessTemplates(i interface{}, filterFuncs ...func([]string) ([]string, error)) error
ProcessTemplates is a mocked version
func (*MockProcessor) TemplateExists ¶ added in v1.4.0
func (m *MockProcessor) TemplateExists(fileName string) bool
TemplateExists is a mocked version
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