interpolate

package
v3.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VariablePattern = regexp.MustCompile(`\$\{([A-Z][A-Z0-9_]*)\}`)

VariablePattern matches ${VAR_NAME} syntax

Functions

func ApplyTypeCorrections

func ApplyTypeCorrections(data interface{}, r *Resolver) interface{}

ApplyTypeCorrections walks a parsed JSON/YAML value and converts string values that were produced by integer-typed variable interpolation back to Go integers, ensuring they encode as JSON numbers rather than quoted strings.

func ExtractAllVariables

func ExtractAllVariables(strings ...string) []string

ExtractAllVariables scans multiple strings and returns all unique variable names

func ExtractVariables

func ExtractVariables(s string) []string

ExtractVariables finds all ${VAR_NAME} patterns in a string and returns unique variable names

func HasVariables

func HasVariables(s string) bool

HasVariables checks if a string contains any ${VAR_NAME} patterns

Types

type Resolver

type Resolver struct {
	// Variables tracks all discovered variables and their values
	Variables map[string]string
	// Generated tracks which variables were auto-generated (not from env)
	Generated map[string]bool
	// VarTypes holds declared types for variables from a VARS block ("uuid", "integer", "string", "enum")
	VarTypes map[string]string
	// VarConstraints holds per-variable key=value constraint maps from a VARS block
	VarConstraints map[string]map[string]string
}

Resolver handles environment variable substitution with generated values

func NewResolver

func NewResolver() *Resolver

NewResolver creates a new Resolver with empty variable sets

func (*Resolver) DeclareVariable

func (r *Resolver) DeclareVariable(name, varType string, constraints map[string]string) error

DeclareVariable records a type declaration and optional constraints for a variable and pre-generates its value. Called by the DSL parser when it processes a VARS block.

func (*Resolver) FormatVarMap

func (r *Resolver) FormatVarMap() string

FormatVarMap returns a human-readable summary of all resolved variables, suitable for appending to a test failure message to aid debugging.

func (*Resolver) GetGeneratedEnv

func (r *Resolver) GetGeneratedEnv() []string

GetGeneratedEnv returns environment variable assignments for all generated values This is used to inject variables into containers

func (*Resolver) Resolve

func (r *Resolver) Resolve(s string) string

Resolve substitutes all ${VAR_NAME} patterns in a string with their values If a variable is not set in the environment and not already in Variables, it generates a random value

func (*Resolver) ResolveMap

func (r *Resolver) ResolveMap(m map[string]string) map[string]string

ResolveMap substitutes variables in all string values of a map

Jump to

Keyboard shortcuts

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