interpolate

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 6 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 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
}

Resolver handles environment variable substitution with generated values

func NewResolver

func NewResolver() *Resolver

NewResolver creates a new Resolver with empty variable sets

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