template

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package template renders Go text/template strings against a workflow.RenderCtx. Strict missing-key handling so typos surface as errors instead of `<no value>`. Used by every executor that needs to interpolate {{.Event.X}} / {{.Node.X.Y}} / {{.Env.X}} / {{.Secret.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'",
}

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)
	},
}

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.

Secret leak guard: `{{.Env.X}}` looks up a secret-tagged key → error. Use `{{.Secret.X}}` explicitly.

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