template

package
v0.97.8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package template provides notification template rendering using Go text/template with Sprig function library support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTemplateFields added in v0.97.8

func ExtractTemplateFields(tmplStr string) []string

ExtractTemplateFields returns unique root payload field names referenced in a template string.

func Init

func Init(templates []manifest.Template) error

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

func SamplePayload(tmpl manifest.Template) map[string]any

SamplePayload builds a sample payload map from a notify template's body and overrides.

func SamplePayloadJSON added in v0.97.8

func SamplePayloadJSON(tmpl manifest.Template) (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 GetEngine

func GetEngine() *Engine

GetEngine returns the global template engine.

func New

func New() *Engine

New creates a new template Engine.

func (*Engine) GetTemplateID

func (e *Engine) GetTemplateID(eventType string) string

GetTemplateID returns the template ID for a given event type. This is a convenience mapping that can be extended.

func (*Engine) HasTemplate

func (e *Engine) HasTemplate(id string) bool

HasTemplate returns true if the given template ID exists in the engine.

func (*Engine) ListTemplateIDs

func (e *Engine) ListTemplateIDs() []string

ListTemplateIDs returns all registered template IDs in the engine.

func (*Engine) ListTemplates added in v0.97.8

func (e *Engine) ListTemplates() []manifest.Template

ListTemplates returns all registered template manifests sorted by ID.

func (*Engine) LoadConfig

func (e *Engine) LoadConfig(templates []manifest.Template) error

LoadConfig loads templates and compiles all templates.

func (*Engine) Render

func (e *Engine) Render(templateID, channel string, data map[string]any) (*RenderResult, error)

Render renders a template by ID for a specific channel with the given data payload. It first looks for a channel-specific override, falling back to the default template.

type RenderResult

type RenderResult struct {
	Title  string
	Body   string
	Format string
}

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.

Jump to

Keyboard shortcuts

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