vars

package
v0.9.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Extract

func Extract(ctx context.Context, input string) []string

Extract is a convenience function to extract template variables from a string

func Process

func Process(ctx context.Context, input string, varCtx VariableContext) (string, error)

Process is a convenience function to process a template string

func ProcessMap

func ProcessMap(ctx context.Context, input map[string]string, varCtx VariableContext) (map[string]string, error)

ProcessMap is a convenience function to process a map of template strings

func RegisterVariable

func RegisterVariable(ctx context.Context, name string, processor VariableFunc)

RegisterVariable is a convenience function to register a custom variable processor

func WithProcessor

func WithProcessor(ctx context.Context, processor VariableProcessor) context.Context

WithProcessor returns a new context with the template processor

Types

type DefaultVariableContext

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

DefaultVariableContext is the default implementation of VariableContext

func NewContext

func NewContext() *DefaultVariableContext

NewContext is a convenience function to create a new variable context

func NewVariableContext

func NewVariableContext() *DefaultVariableContext

NewVariableContext creates a new DefaultVariableContext

func (*DefaultVariableContext) AddPod

func (c *DefaultVariableContext) AddPod(name, dnsName string)

AddPod adds a pod to the context

func (*DefaultVariableContext) GetPodName

func (c *DefaultVariableContext) GetPodName(name string) string

GetPodName returns the internal DNS name for a pod

func (*DefaultVariableContext) GetRegistry

func (c *DefaultVariableContext) GetRegistry() string

GetRegistry returns the registry URL

func (*DefaultVariableContext) GetURL

func (c *DefaultVariableContext) GetURL() string

GetURL returns the application URL

func (*DefaultVariableContext) GetValue

func (c *DefaultVariableContext) GetValue(name string) (string, bool)

GetValue returns a custom variable value

func (*DefaultVariableContext) SetRegistry

func (c *DefaultVariableContext) SetRegistry(registry string)

SetRegistry sets the registry URL

func (*DefaultVariableContext) SetURL

func (c *DefaultVariableContext) SetURL(url string)

SetURL sets the application URL

func (*DefaultVariableContext) SetValue

func (c *DefaultVariableContext) SetValue(name, value string)

SetValue sets a custom variable value

func (*DefaultVariableContext) WithPod

func (c *DefaultVariableContext) WithPod(name, dnsName string) *DefaultVariableContext

WithPod returns a new context with a pod added

func (*DefaultVariableContext) WithRegistry

func (c *DefaultVariableContext) WithRegistry(registry string) *DefaultVariableContext

WithRegistry returns a new context with the registry set

func (*DefaultVariableContext) WithURL

WithURL returns a new context with the URL set

func (*DefaultVariableContext) WithValue

func (c *DefaultVariableContext) WithValue(name, value string) *DefaultVariableContext

WithValue returns a new context with a custom value set

type DefaultVariableProcessor

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

DefaultVariableProcessor is the default implementation of VariableProcessor

func NewVariableProcessor

func NewVariableProcessor() *DefaultVariableProcessor

NewVariableProcessor creates a new DefaultVariableProcessor

func (*DefaultVariableProcessor) Extract

func (p *DefaultVariableProcessor) Extract(input string) []string

Extract extracts template variables from the given string

func (*DefaultVariableProcessor) ExtractPodReferences

func (p *DefaultVariableProcessor) ExtractPodReferences(input string) []string

ExtractPodReferences extracts pod references from the given string

func (*DefaultVariableProcessor) Process

func (p *DefaultVariableProcessor) Process(input string, context VariableContext) (string, error)

Process replaces template variables in the given string with their values

func (*DefaultVariableProcessor) ProcessMap

func (p *DefaultVariableProcessor) ProcessMap(input map[string]string, context VariableContext) (map[string]string, error)

ProcessMap replaces template variables in all values of the given map

func (*DefaultVariableProcessor) RegisterVariable

func (p *DefaultVariableProcessor) RegisterVariable(name string, processor VariableFunc)

RegisterVariable registers a custom variable processor

type VariableContext

type VariableContext interface {
	// GetRegistry returns the registry URL
	GetRegistry() string

	// GetURL returns the application URL
	GetURL() string

	// GetPodName returns the internal DNS name for a pod
	GetPodName(name string) string

	// GetValue returns a custom variable value
	GetValue(name string) (string, bool)
}

VariableContext provides context for variable processing

type VariableFunc

type VariableFunc func(context VariableContext, args ...string) (string, error)

VariableFunc is a function that processes a template variable

type VariableProcessor

type VariableProcessor interface {
	// Process replaces template variables in the given string with their values
	Process(input string, context VariableContext) (string, error)

	// ProcessMap replaces template variables in all values of the given map
	ProcessMap(input map[string]string, context VariableContext) (map[string]string, error)

	// Extract extracts template variables from the given string
	Extract(input string) []string

	// RegisterVariable registers a custom variable processor
	RegisterVariable(name string, processor VariableFunc)
}

VariableProcessor defines the interface for processing template variables

func GetProcessor

func GetProcessor(ctx context.Context) VariableProcessor

GetProcessor returns the template processor from the context or the default processor

Jump to

Keyboard shortcuts

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