template

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultReplacementAppliedFunc added in v1.16.0

func DefaultReplacementAppliedFunc(substring string, mapping Mapping, cfg *Config) (string, bool, error)

func DefaultReplacementFunc added in v1.15.0

func DefaultReplacementFunc(substring string, mapping Mapping, cfg *Config) (string, error)

func ExtractVariables

func ExtractVariables(configDict map[string]interface{}, pattern *regexp.Regexp) 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(template string, mapping Mapping) (string, error)

Substitute variables in the string with their values

func SubstituteWith

func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, subsFuncs ...SubstituteFunc) (string, error)

SubstituteWith substitute variables in the string with their values. It accepts additional substitute function.

func SubstituteWithOptions added in v1.15.0

func SubstituteWithOptions(template string, mapping Mapping, options ...Option) (string, error)

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

func WithoutLogging added in v1.15.0

func WithoutLogging(cfg *Config)

Types

type Config added in v1.15.0

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

type InvalidTemplateError

type InvalidTemplateError struct {
	Template string
}

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

func (InvalidTemplateError) Error

func (e InvalidTemplateError) Error() string

type Mapping

type Mapping func(string) (string, bool)

Mapping 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 MissingRequiredError added in v1.13.4

type MissingRequiredError struct {
	Variable string
	Reason   string
}

MissingRequiredError is returned when a variable template is missing

func (MissingRequiredError) Error added in v1.13.4

func (e MissingRequiredError) Error() string

type Option added in v1.15.0

type Option func(*Config)

func WithPattern added in v1.15.0

func WithPattern(pattern *regexp.Regexp) Option

func WithReplacementFunction added in v1.15.0

func WithReplacementFunction(replacementFunc ReplacementFunc) Option

func WithSubstitutionFunction added in v1.15.0

func WithSubstitutionFunction(subsFunc SubstituteFunc) Option

type ReplacementFunc added in v1.15.0

type ReplacementFunc func(string, Mapping, *Config) (string, error)

ReplacementFunc is a user-supplied function that is apply to the matching substring. Returns the value as a string and an error.

type SubstituteFunc

type SubstituteFunc func(string, Mapping) (string, bool, error)

SubstituteFunc is a user-supplied function that apply substitution. Returns the value as a string, a bool indicating if the function could apply the substitution and an error.

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