template

package
v1.3.27 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package template provides template rendering and variable substitution.

This package implements a flexible template system that can be used by both prompts and personas. It supports:

  • Variable substitution with {{variable}} syntax
  • Recursive template resolution (variables can contain other variables)
  • Validation of required variables
  • Detection of unresolved placeholders

Future versions may support more advanced templating engines like Go templates (similar to Helm charts) for conditional logic, loops, and functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUsedVars

func GetUsedVars(vars map[string]string) []string

GetUsedVars returns a list of variable names that had non-empty values. This is useful for debugging and logging which variables were actually used.

Types

type RenderResult added in v1.3.26

type RenderResult struct {
	Text       string            // final rendered text
	UsedVars   map[string]string // variables that were substituted
	UnusedVars []string          // variables available but not referenced
	Passes     int               // number of recursive passes performed
}

RenderResult contains the rendered text and metadata about the rendering process.

type Renderer

type Renderer struct {
}

Renderer handles variable substitution in templates

func NewRenderer

func NewRenderer() *Renderer

NewRenderer creates a new template renderer

func (*Renderer) MergeVars

func (r *Renderer) MergeVars(varMaps ...map[string]string) map[string]string

MergeVars merges multiple variable maps with later maps taking precedence. This is useful for combining default values, context variables, and overrides.

Example:

defaults := map[string]string{"color": "blue", "size": "medium"}
overrides := map[string]string{"color": "red"}
result := MergeVars(defaults, overrides)
// result = {"color": "red", "size": "medium"}

func (*Renderer) Render

func (r *Renderer) Render(templateText string, vars map[string]string) (string, error)

Render applies variable substitution to the template with recursive resolution.

The renderer performs multiple passes (up to maxPasses) to handle nested variable substitution. For example, if var1="{{var2}}" and var2="value", the final result will correctly resolve to "value".

Returns an error if any placeholders remain unresolved after all passes.

func (*Renderer) RenderDetailed added in v1.3.26

func (r *Renderer) RenderDetailed(templateText string, vars map[string]string) (*RenderResult, error)

RenderDetailed applies variable substitution and returns detailed rendering metadata.

func (*Renderer) ValidateRequiredVars

func (r *Renderer) ValidateRequiredVars(requiredVars []string, vars map[string]string) error

ValidateRequiredVars checks that all required variables are provided and non-empty. Returns an error listing any missing variables.

Jump to

Keyboard shortcuts

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