Documentation
¶
Overview ¶
Package template provides notification template rendering using Go text/template with Sprig function library support.
Index ¶
- func ExtractTemplateFields(tmplStr string) []string
- func Init(templates []manifest.Template) error
- func ResetForTest()
- func SamplePayload(tmpl manifest.Template) map[string]any
- func SamplePayloadJSON(tmpl manifest.Template) (string, error)
- type Engine
- func (e *Engine) GetTemplateID(eventType string) string
- func (e *Engine) HasTemplate(id string) bool
- func (e *Engine) ListTemplateIDs() []string
- func (e *Engine) ListTemplates() []manifest.Template
- func (e *Engine) LoadConfig(templates []manifest.Template) error
- func (e *Engine) Render(templateID, channel string, data map[string]any) (*RenderResult, error)
- type RenderResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractTemplateFields ¶ added in v0.97.8
ExtractTemplateFields returns unique root payload field names referenced in a template string.
func Init ¶
Init loads templates into the global engine. It is safe to call multiple times (on reload after CRUD).
func ResetForTest ¶ added in v0.97.8
func ResetForTest()
ResetForTest clears the global template engine. Intended for tests only.
func SamplePayload ¶ added in v0.97.8
SamplePayload builds a sample payload map from a notify template's body and overrides.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine renders notification templates for different channels using Sprig functions.
func (*Engine) GetTemplateID ¶
GetTemplateID returns the template ID for a given event type. This is a convenience mapping that can be extended.
func (*Engine) HasTemplate ¶
HasTemplate returns true if the given template ID exists in the engine.
func (*Engine) ListTemplateIDs ¶
ListTemplateIDs returns all registered template IDs in the engine.
func (*Engine) ListTemplates ¶ added in v0.97.8
ListTemplates returns all registered template manifests sorted by ID.
func (*Engine) LoadConfig ¶
LoadConfig loads templates and compiles all templates.
type RenderResult ¶
RenderResult holds the output of template rendering for a specific channel.
func RenderString ¶ added in v0.97.8
func RenderString(tmplStr, format string, data map[string]any) (*RenderResult, error)
RenderString compiles and renders an ad-hoc template string (playground / custom body). Empty format defaults to markdown. Title is taken from the first line of the body.