template

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package template renders Go text/template strings against a workflow.RenderCtx. Missing map keys use missingkey=zero so a payload that simply lacks an optional field (e.g. a webhook body without an "action" key) does NOT fail the node — it renders the map element's zero value and the run continues. Note: for the map[string]any payloads wick passes, that zero value is nil, which text/template prints as the literal "<no value>"; wrap optional fields in `default` (e.g. {{ .Event.Payload.action | default "" }}) when you want a clean empty string. This matches the parse-time validator (parse.go uses missingkey=zero too) so a template that validates also runs. Used by every executor that interpolates {{.Event.X}} / {{.Node.X.Y}} / {{.Env.X}}. All env vars — plain and secret — are accessible via {{.Env.X}}.

Index

Constants

This section is empty.

Variables

View Source
var BuiltinFuncDocs = map[string]string{
	"truncate n str":      "truncate str to n chars, appends '…'",
	"upper str":           "uppercase",
	"lower str":           "lowercase",
	"trim str":            "trim whitespace",
	"default d v":         "return v if non-empty, else d",
	"toJSON v":            "marshal any value to JSON string — safe for body: fields (aliases: toJson, tojson)",
	"fromJSON s":          "parse JSON string to map/slice/scalar — use to read fields out of stringified JSON (aliases: fromJson, fromjson)",
	"jsonEscape str":      "escape string for embedding inside a JSON string literal",
	"now format":          "current UTC time — format uses Go ref time e.g. '2006-01-02T15:04:05Z07:00'",
	"timeFormat t format": "format a time.Time from context (e.g. .Event.At) — same Go ref-time format. Example: {{.Event.At | timeFormat \"2006-01-02T15:04:05Z\"}}",
}

BuiltinFuncDocs is the single source of truth for available template functions. Key = "funcname signature", Value = description. Exposed via workflow_workspace so AI always sees the up-to-date list.

View Source
var BuiltinFuncs = gotemplate.FuncMap{
	"truncate": func(n int, s string) string {
		if len(s) <= n {
			return s
		}
		return s[:n] + "…"
	},
	"upper": strings.ToUpper,
	"lower": strings.ToLower,
	"trim":  strings.TrimSpace,
	"default": func(d, v any) any {
		if v == nil || v == "" {
			return d
		}
		return v
	},

	"toJSON":   toJSON,
	"toJson":   toJSON,
	"tojson":   toJSON,
	"fromJSON": fromJSON,
	"fromJson": fromJSON,
	"fromjson": fromJSON,

	"jsonEscape": func(s string) string {
		b, _ := json.Marshal(s)

		return string(b[1 : len(b)-1])
	},

	"now": func(format string) string {
		if format == "" {
			format = time.RFC3339
		}
		return time.Now().UTC().Format(format)
	},

	"timeFormat": func(t time.Time, format string) string {
		if format == "" {
			format = time.RFC3339
		}
		return t.UTC().Format(format)
	},
}

BuiltinFuncs are convenience template funcs available in every Render.

Functions

func Render

func Render(tmpl string, ctx workflow.RenderCtx) (string, error)

Render parses + executes a Go template with strict missing-key handling. All env vars (plain + encrypted secrets) are decrypted before rendering and available via {{.Env.X}}.

func RenderInto

func RenderInto(v any, ctx workflow.RenderCtx) (any, error)

RenderInto recursively renders string values inside maps/slices. Used for node `args:` maps and HTTP headers/query.

Types

This section is empty.

Jump to

Keyboard shortcuts

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