template

package
v3.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRecursionDepth = 250
)

MaxRecursionDepth is the maximum allowed nesting depth for ProcessMap/ProcessStream.

Variables

View Source
var ErrMaxRecursionDepthExceeded = errors.New("maximum recursion depth exceeded")

ErrMaxRecursionDepthExceeded is returned when structure nesting exceeds MaxRecursionDepth.

Functions

func Functions

func Functions(ctx context.Context, reg pkgplugins.Registry) map[string]any

func HasTemplatesInHeaders

func HasTemplatesInHeaders(headers map[string]string) bool

HasTemplatesInHeaders reports whether any header value contains a template.

func IsTemplateString

func IsTemplateString(s string) bool

IsTemplateString checks if a string contains template syntax. The closing delimiter must appear AFTER the opening one — "a }} b {{ c" is not a template.

Types

type Data

type Data struct {
	Request      map[string]any `json:"request"`
	Headers      map[string]any `json:"headers"`
	MessageIndex int            `json:"messageIndex"`
	RequestTime  time.Time      `json:"requestTime"`
	// Timestamp is a backward-compatibility alias for RequestTime
	Timestamp     time.Time      `json:"timestamp"`
	State         map[string]any `json:"state"`
	Requests      []any          `json:"requests"`
	AttemptNumber int            `json:"attemptNumber"` // Current attempt number (1-based)
	// AttemptIndex is a backward-compatibility alias for AttemptNumber
	AttemptIndex int `json:"attemptIndex"`
	MaxAttempts  int `json:"maxAttempts"` // Maximum number of attempts for this stub
	// TotalAttempts is a backward-compatibility alias for MaxAttempts
	TotalAttempts int    `json:"totalAttempts"`
	StubID        string `json:"stubId"` // Unique identifier of the stub
	// RequestID is a backward-compatibility alias mapped to StubID
	RequestID string `json:"requestId"`
}

Data represents the context data available for template rendering.

type Engine

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

Engine provides template rendering functionality.

func New

func New(ctx context.Context, reg plugins.Registry) *Engine

New creates a new template engine with custom functions.

func (*Engine) ProcessError

func (e *Engine) ProcessError(errorStr string, templateData Data) (string, error)

ProcessError processes error template.

func (*Engine) ProcessHeaders

func (e *Engine) ProcessHeaders(headers map[string]string, templateData Data) error

ProcessHeaders processes templates in headers.

func (*Engine) ProcessMap

func (e *Engine) ProcessMap(data map[string]any, templateData Data) error

ProcessMap processes templates in a map recursively.

func (*Engine) Render

func (e *Engine) Render(tmpl string, data Data) (result string, err error)

Render renders a template string with the given data.

Jump to

Keyboard shortcuts

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