template

package
v1.1.26 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

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 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
	Required     bool
}

Jump to

Keyboard shortcuts

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