Documentation
¶
Overview ¶
Package emailtemplate is the hand-rolled variable-interpolation engine for user email templates (beta). It deliberately implements a flat subset of Mustache — `{{ident}}` (escaped under EscapeHTML) and `{{{ident}}}` (raw) — with NO third-party dependency, and reserves Mustache's structural syntax (`{{#…}}`, `{{/…}}`, `{{^…}}`, `{{>…}}`, `{{!…}}`) as a parse error so a future upgrade to sections/partials/comments stays purely additive: no template that parses today can change meaning later.
The API is two-phase — Parse then Render — so the create/validate endpoints can reject bad syntax without any data, and the send path can render one parsed part against caller-supplied template_data. Missing variables render as the empty string (the permissive Postmark model); a path that resolves to an object or array also renders empty.
Index ¶
Constants ¶
const ( // MaxSourceBytes caps one template part's source at Parse time. MaxSourceBytes = 256 * 1024 // MaxDataDepth caps template_data nesting (maps/arrays) at Render time. MaxDataDepth = 8 // MaxRenderedBytes caps one rendered part at Render time. MaxRenderedBytes = 2 * 1024 * 1024 )
Caps. Enforced here so every caller (create, validate, send) shares one definition; the outbound path re-validates rendered output independently.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EscapeMode ¶
type EscapeMode int
EscapeMode selects how `{{ident}}` output is encoded. `{{{ident}}}` is always raw.
const ( // EscapeNone renders both `{{x}}` and `{{{x}}}` verbatim — used for the // subject and plain-text body, where HTML entities would be garbage. EscapeNone EscapeMode = iota // EscapeHTML HTML-escapes `{{x}}` (and leaves `{{{x}}}` raw) — used for // html_body so interpolated user data can't inject markup by default. EscapeHTML )
type ParseError ¶
ParseError describes a syntax error with its byte offset in the source.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a parsed template part, safe for concurrent Render calls.
func Parse ¶
Parse compiles a template part. It fails on source over MaxSourceBytes, unclosed tags, empty tags, invalid identifiers, and reserved (Mustache structural) syntax.