template

package
v2.4.6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPattern = regexp.MustCompile(patternString)

Functions

func DefaultReplacementAppliedFunc

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

func DefaultReplacementFunc

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 compose file (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

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

func WithoutLogging(cfg *Config)

Types

type Config

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

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 Option

type Option func(*Config)

func WithPattern

func WithPattern(pattern *regexp.Regexp) Option

func WithReplacementFunction

func WithReplacementFunction(replacementFunc ReplacementFunc) Option

func WithSubstitutionFunction

func WithSubstitutionFunction(subsFunc SubstituteFunc) Option

type ReplacementFunc

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