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() error
- func ResetForTest()
- func SamplePayload(tmpl config.NotifyTemplate) map[string]any
- func SamplePayloadJSON(tmpl config.NotifyTemplate) (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() []config.NotifyTemplate
- func (e *Engine) LoadConfig(templates []config.NotifyTemplate) 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.96.2
ExtractTemplateFields returns unique root payload field names referenced in a template string.
func Init ¶
func Init() error
Init loads templates from configuration into the global engine. It is safe to call multiple times (on config reload).
func ResetForTest ¶ added in v0.96.2
func ResetForTest()
ResetForTest clears the global template engine. Intended for tests only.
func SamplePayload ¶ added in v0.96.2
func SamplePayload(tmpl config.NotifyTemplate) map[string]any
SamplePayload builds a sample payload map from a notify template's body and overrides.
func SamplePayloadJSON ¶ added in v0.96.2
func SamplePayloadJSON(tmpl config.NotifyTemplate) (string, error)
SamplePayloadJSON returns pretty-printed JSON for SamplePayload.
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.96.2
func (e *Engine) ListTemplates() []config.NotifyTemplate
ListTemplates returns all registered template manifests sorted by ID.
func (*Engine) LoadConfig ¶
func (e *Engine) LoadConfig(templates []config.NotifyTemplate) error
LoadConfig loads templates from notify configuration and compiles all templates.
type RenderResult ¶
RenderResult holds the output of template rendering for a specific channel.
func RenderString ¶ added in v0.96.2
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.