varsystem

package
v0.0.0-...-110f058 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = fmt.Errorf("key not found")
	ErrInvalidKey  = fmt.Errorf("invalid key")
)

Functions

func CheckIsVar

func CheckIsVar(varKey string) bool

func CheckPrefix

func CheckPrefix(varKey string) bool

func CheckStringHasAnyVarKey

func CheckStringHasAnyVarKey(raw string) bool

func CheckSuffix

func CheckSuffix(varKey string) bool

func ExtractVarKeys

func ExtractVarKeys(raw string) []string

ExtractVarKeys extracts all variable keys from a string without resolving them. Returns a deduplicated list of variable keys (e.g., "nodeName.field", "userId"). Skips special references like #env: and #file:.

func ExtractVarKeysFromMultiple

func ExtractVarKeysFromMultiple(strs ...string) []string

ExtractVarKeysFromMultiple extracts variable keys from multiple strings and returns a deduplicated list.

func FilterVars

func FilterVars(vars []menv.Variable, filter func(menv.Variable) bool) []menv.Variable

func GetIsFileReferencePath

func GetIsFileReferencePath(filePath string) string

func GetVarKeyFromRaw

func GetVarKeyFromRaw(raw string) string

{{varKey}}

func HelperNewAny

func HelperNewAny(vars *[]menv.Variable, target any, prefix string)

func IsEnvReference

func IsEnvReference(key string) bool

IsEnvReference checks if a variable key refers to an environment variable (starts with "#env:")

func IsFileReference

func IsFileReference(key string) bool

IsFileReference checks if a variable key refers to a file (starts with "file:")

func MergeVars

func MergeVars(global, current []menv.Variable) []menv.Variable

Helper functions

func ReadEnvValueAsString

func ReadEnvValueAsString(ref string) (string, error)

ReadEnvValueAsString resolves a #env: reference to its environment value.

func ReadFileContentAsString

func ReadFileContentAsString(filePath string) (string, error)

ReadFileContentAsString reads the content of a file at the given path

Types

type VarMap

type VarMap map[string]menv.Variable

func MergeVarMap

func MergeVarMap(varMap1, varMap2 VarMap) VarMap

MergeVarMap merges two var maps it creates a new var map and does not modify the original var maps

func NewVarMap

func NewVarMap(vars []menv.Variable) VarMap

func NewVarMapFromAnyMap

func NewVarMapFromAnyMap(anyMap map[string]any) VarMap

func NewVarMapWithPrefix

func NewVarMapWithPrefix(vars []menv.Variable, prefix string) VarMap

func (VarMap) Get

func (vm VarMap) Get(varKey string) (menv.Variable, bool)

func (VarMap) ReplaceVars

func (vm VarMap) ReplaceVars(raw string) (string, error)

ReplaceVars replaces {{ varKey }} patterns with values from the VarMap.

LIMITATION: This method only does simple key lookup. It does NOT support:

  • Expressions: {{ a + b }}, {{ count > 5 }}
  • Function calls: {{ now() }}, {{ len(items) }}
  • Only works with pre-flattened keys like "user.name" (not nested access)

RECOMMENDED: Use expression.UnifiedEnv for full expression support:

// Old way (limited):
varMap := varsystem.NewVarMapFromAnyMap(varMapCopy)
result, err := varMap.ReplaceVars(raw)

// New way (full expression support):
env := expression.NewUnifiedEnv(varMapCopy)
result, err := env.Interpolate(raw)

Example: "{{ url }}/api/{{ version }}/path" returns "google.com/api/v1/path"

func (VarMap) ToSlice

func (vm VarMap) ToSlice() []menv.Variable

type VarMapTracker

type VarMapTracker struct {
	VarMap   VarMap
	ReadVars map[string]string // stores variable key -> resolved value
}

VarMapTracker wraps a VarMap and tracks variable reads

func NewVarMapTracker

func NewVarMapTracker(varMap VarMap) *VarMapTracker

NewVarMapTracker creates a new tracking wrapper around a VarMap

func (*VarMapTracker) Get

func (vmt *VarMapTracker) Get(varKey string) (menv.Variable, bool)

Get tracks variable access and delegates to the underlying VarMap

func (*VarMapTracker) GetReadVars

func (vmt *VarMapTracker) GetReadVars() map[string]string

GetReadVars returns a copy of all tracked variable reads

func (*VarMapTracker) ReplaceVars

func (vmt *VarMapTracker) ReplaceVars(raw string) (string, error)

ReplaceVars tracks all variable reads during replacement and delegates to underlying VarMap.

LIMITATION: Same as VarMap.ReplaceVars() - only simple key lookup, no expressions.

RECOMMENDED: For full expression support with tracking, use expression.UnifiedEnv:

env := expression.NewUnifiedEnv(varMapCopy).WithTracking(tracker)
result, err := env.Interpolate(raw)

Jump to

Keyboard shortcuts

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