render

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package render interpolates the library's namespaced templates and evaluates expr conditions against a read-only view. It never exposes host objects with methods and never runs anything: a value that only exists at run time is reported as deferred.

Index

Constants

This section is empty.

Variables

View Source
var ErrDeferred = errors.New("taskrun: value requires execution")

ErrDeferred marks a value that only exists at run time. Inspect reports it as deferred instead of executing anything.

Functions

func CompileCondition

func CompileCondition(source string, rv Vars) (func() (bool, error), error)

CompileCondition compiles an expr condition against the read-only view. A condition may read vars, env, args, host and run metadata; it cannot call host methods. A condition that needs a declared dynamic variable resolves it through Vars.Dynamic, which Inspect leaves nil so the condition is reported as deferred instead of running a command.

func DetectCycle

func DetectCycle(level map[string]any) error

DetectCycle rejects static variable cycles. Only same-level references can form a cycle, so this check is decidable at load time, before any request runs.

func LookupEnv

func LookupEnv(env map[string]string, name string) (string, bool)

LookupEnv resolves an environment name honoring Windows case-insensitivity.

func ReferencesAny

func ReferencesAny(source string, names []string) bool

ReferencesAny reports whether source mentions any of the identifiers as a standalone word. It decides whether a condition needs a dynamic variable, which Inspect must not evaluate.

func Refs

func Refs(value string) []string

Refs returns the variable names interpolated through ${vars.*}.

func Render

func Render(source string, rv Vars) (string, error)

Render performs a single-pass interpolation of explicitly namespaced templates. "$${" escapes a literal "${". Unknown references are errors.

func ResolveLevel

func ResolveLevel(level map[string]any, base Vars) (map[string]any, error)

ResolveLevel evaluates one level of static variables in dependency order. Unresolved references and cycles are definition errors.

Types

type Error

type Error struct {
	Kind Kind
	Msg  string
}

Error is a rendering failure. Msg is the complete user facing message.

func (*Error) Error

func (e *Error) Error() string

type Kind

type Kind int

Kind classifies a rendering failure so the caller can map it onto its own error kinds.

const (
	// KindInvalidDefinition reports a definition that cannot be rendered.
	KindInvalidDefinition Kind = iota
	// KindInvalidRequest reports a request that cannot be satisfied.
	KindInvalidRequest
)

type Vars

type Vars struct {
	Vars map[string]any
	Env  map[string]string
	Args []string
	Host map[string]any
	Run  map[string]any
	// Dynamic resolves a declared dynamic variable on demand. Inspect leaves it
	// nil so that no command runs; a lookup then reports ErrDeferred.
	Dynamic func(name string) (any, bool, error)
	// DeferredNames lists the dynamic variable names declared for this level.
	DeferredNames []string
}

Vars is the read-only view available to template interpolation and condition evaluation.

Jump to

Keyboard shortcuts

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