render

package
v0.0.0-...-eb6cc14 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package render compiles and evaluates a route's Go-template fields — title, message, and the params/headers values. Templates are parsed once at load (fail-fast) and rendered per request against the webhook payload with the shared funcmap (sprout helpers plus a strict env; no filesystem or network). Missing keys are tolerated (`<no value>`), matching the gate's dyn/missing-key handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Payload any
	Headers map[string]string
	Query   map[string]string
	Method  string
	Route   string
	Now     time.Time
}

Data is the variable environment a field template renders against. The typed fields are projected (by vars) onto lower-cased template variables — .payload, .headers, .query, .method, .route, .now — so a route's templates use the same names as the CEL gate.

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is a compiled set of named value-templates — a route's params or headers. Keys are literal; values are templates.

func CompileMap

func CompileMap(field string, m map[string]string) (*Map, error)

CompileMap parses every value in m with no shared snippets.

func (*Map) Render

func (m *Map) Render(d Data) (out map[string]string, dropped map[string]error)

Render evaluates every entry. A key whose value errors at render is an optional-field fault: it is omitted from the result and reported in dropped, and the relay proceeds. A nil dropped map means every key rendered.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is a compiled collection of named template snippets (the top-level `templates:` block). It is shared across a config's routes so any field template can reuse a snippet via {{ template "name" . }} or {{ include "name" . }}; snippets may reference one another. Build it once at load.

func NewSet

func NewSet(snippets map[string]string) (*Set, error)

NewSet parses the named snippets into a shared template tree and validates their reference graph: every {{ template }} / include reference must resolve to a declared snippet, no snippet may reference a reserved name, and the graph must be acyclic. The graph checks matter because include re-enters via ExecuteTemplate (resetting text/template's depth guard), so a cycle would recurse until the goroutine stack overflows — a runtime-fatal crash recover() cannot catch. Validating here makes that, and a dangling reference, a load-time failure (boot / `chaski validate`) instead of a render-time fault.

func (*Set) Compile

func (s *Set) Compile(name, text string) (*Template, error)

Compile parses one field template into a clone of the snippet tree, so the field can reference any snippet. A reference to an excluded function (e.g. readFile) is a parse error here, so the restriction is enforced at load, not silently at render.

func (*Set) CompileMap

func (s *Set) CompileMap(field string, m map[string]string) (*Map, error)

CompileMap parses every value in m against this set's snippets. A parse error in any value fails at load, named by its key.

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template is one compiled field template.

func Compile

func Compile(name, text string) (*Template, error)

Compile parses one field template with no shared snippets.

func (*Template) Render

func (t *Template) Render(d Data) (string, error)

Render executes the template against d.

func (*Template) Source

func (t *Template) Source() string

Source returns the original template text.

Jump to

Keyboard shortcuts

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