template

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultMissingKeyCallback added in v0.10.0

func DefaultMissingKeyCallback(ctx context.Context, input string) func(string)

func ExtractVariables

func ExtractVariables(ctx context.Context, configDict any) map[string]Variable

ExtractVariables returns a map of all the variables defined in the specified composefile (dict representation) and their default value if any.

func Substitute

func Substitute(ctx context.Context, input string, resolver Resolver, accessibleVariables AccessibleVariables) (string, error)

SubstituteWithOptions substitute variables in the string with their values. It accepts additional options such as a custom function or pattern.

Types

type AccessibleVariables added in v0.10.0

type AccessibleVariables func() map[string]string

type EnvironmentHelper added in v0.9.0

type EnvironmentHelper struct {
	Resolver            Resolver
	AccessibleVariables AccessibleVariables
	MissingKeyCallback  func(string)
}

func (EnvironmentHelper) Each added in v0.9.0

func (l EnvironmentHelper) Each(callback func(name string, vr expand.Variable) bool)

func (EnvironmentHelper) Get added in v0.9.0

func (helper EnvironmentHelper) Get(name string) expand.Variable

type InvalidTemplateError

type InvalidTemplateError struct {
	Template string
	Wrapped  error
}

InvalidTemplateError is returned when a variable template is not in a valid format

func (InvalidTemplateError) Error

func (e InvalidTemplateError) Error() string

type MissingRequiredError

type MissingRequiredError struct {
	Variable string
	Reason   string
}

MissingRequiredError is returned when a variable template is missing

func (MissingRequiredError) Error

func (e MissingRequiredError) Error() string

type Resolver added in v0.9.0

type Resolver func(string) (string, bool)

Resolver is a user-supplied function which maps from variable names to values. Returns the value as a string and a bool indicating whether the value is present, to distinguish between an empty string and the absence of a value.

type Variable

type Variable struct {
	Name          string
	DefaultValue  string
	PresenceValue string
	Required      bool
}

Jump to

Keyboard shortcuts

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