template

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package template provides Mustache template rendering functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertSliceToMaps

func ConvertSliceToMaps(slice any) []map[string]any

ConvertSliceToMaps converts a slice of structs to a slice of maps.

func PreprocessModelData

func PreprocessModelData(modelMaps []map[string]any) []map[string]any

PreprocessModelData adds synthetic fields for Mustache template compatibility.

func PreprocessOperationData

func PreprocessOperationData(opMaps []map[string]any) []map[string]any

PreprocessOperationData adds synthetic fields for Mustache template compatibility. The Java Mustache library supports ".0" syntax for checking if an array has elements, but the Go cbroglie/mustache library does not. This function adds boolean "has*" fields.

func ToTemplateData

func ToTemplateData(data any) map[string]any

ToTemplateData converts any struct or data to a map suitable for template rendering.

Types

type Engine

type Engine struct {
	// TemplateDir is the directory containing templates
	TemplateDir string

	// Custom lambdas for templates
	Lambdas map[string]func(text string, render mustache.RenderFunc) (string, error)

	// Verbose enables debug logging of template execution
	Verbose bool
	// contains filtered or unexported fields
}

Engine handles Mustache template rendering.

func NewEngine

func NewEngine(templateDir string) *Engine

NewEngine creates a new template engine.

func NewEngineFromFS

func NewEngineFromFS(fsys fs.FS, subdir string) *Engine

NewEngineFromFS creates a new template engine from an embedded filesystem. The subdir parameter specifies the subdirectory within the fs.FS to use as the template root (e.g., "typescript-fetch").

func (*Engine) LoadPartials

func (e *Engine) LoadPartials() error

LoadPartials loads all partial templates from the template directory.

func (*Engine) LoadPartialsFromFS

func (e *Engine) LoadPartialsFromFS() error

LoadPartialsFromFS loads all partial templates from the embedded filesystem.

func (*Engine) RegisterDefaultLambdas

func (e *Engine) RegisterDefaultLambdas()

RegisterDefaultLambdas registers the default set of lambdas used by openapi-generator.

func (*Engine) RegisterLambda

func (e *Engine) RegisterLambda(name string, fn func(text string, render mustache.RenderFunc) (string, error))

RegisterLambda registers a custom lambda function.

func (*Engine) Render

func (e *Engine) Render(templateName string, data any) (string, error)

Render renders a template with the given data. If the engine was created with NewEngineFromFS, it reads from the embedded filesystem.

func (*Engine) RenderString

func (e *Engine) RenderString(template string, data any) (string, error)

RenderString renders a template string with the given data.

func (*Engine) RenderToFile

func (e *Engine) RenderToFile(templateName string, data any, outputPath string) error

RenderToFile renders a template and writes to a file.

type RenderFunc

type RenderFunc = mustache.RenderFunc

RenderFunc is the function signature for mustache rendering.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL