interpolate

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2016 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncGens = map[string]FuncGenerator{
	"build_name":   funcGenBuildName,
	"build_type":   funcGenBuildType,
	"env":          funcGenEnv,
	"isotime":      funcGenIsotime,
	"pwd":          funcGenPwd,
	"template_dir": funcGenTemplateDir,
	"timestamp":    funcGenTimestamp,
	"uuid":         funcGenUuid,
	"user":         funcGenUser,

	"upper": funcGenPrimitive(strings.ToUpper),
	"lower": funcGenPrimitive(strings.ToLower),
}

Funcs are the interpolation funcs that are available within interpolations.

View Source
var InitTime time.Time

InitTime is the UTC time when this package was initialized. It is used as the timestamp for all configuration templates so that they match for a single build.

Functions

func Funcs

func Funcs(ctx *Context) template.FuncMap

Funcs returns the functions that can be used for interpolation given a context.

func Render

func Render(v string, ctx *Context) (string, error)

Render is shorthand for constructing an I and calling Render.

func RenderInterface

func RenderInterface(v interface{}, ctx *Context) (interface{}, error)

RenderInterface renders any value and returns the resulting value.

func RenderMap

func RenderMap(v interface{}, ctx *Context, f *RenderFilter) (map[string]interface{}, error)

RenderMap renders all the strings in the given interface. The interface must decode into a map[string]interface{}, but is left as an interface{} type to ease backwards compatibility with the way arguments are passed around in Packer.

func Validate

func Validate(v string, ctx *Context) error

Validate is shorthand for constructing an I and calling Validate.

func ValidateInterface

func ValidateInterface(v interface{}, ctx *Context) error

ValidateInterface renders any value and returns the resulting value.

Types

type Context

type Context struct {
	// Data is the data for the template that is available
	Data interface{}

	// Funcs are extra functions available in the template
	Funcs map[string]interface{}

	// UserVariables is the mapping of user variables that the
	// "user" function reads from.
	UserVariables map[string]string

	// EnableEnv enables the env function
	EnableEnv bool

	// All the fields below are used for built-in functions.
	//
	// BuildName and BuildType are the name and type, respectively,
	// of the builder being used.
	//
	// TemplatePath is the path to the template that this is being
	// rendered within.
	BuildName    string
	BuildType    string
	TemplatePath string
}

Context is the context that an interpolation is done in. This defines things such as available variables.

type FuncGenerator

type FuncGenerator func(*Context) interface{}

FuncGenerator is a function that given a context generates a template function for the template.

type I

type I struct {
	Value string
}

I stands for "interpolation" and is the main interpolation struct in order to render values.

func (*I) Render

func (i *I) Render(ctx *Context) (string, error)

Render renders the interpolation with the given context.

func (*I) Validate

func (i *I) Validate(ctx *Context) error

Validate validates that the template is syntactically valid.

type RenderFilter

type RenderFilter struct {
	Include []string
	Exclude []string
	// contains filtered or unexported fields
}

RenderFilter is an option for filtering what gets rendered and doesn't within an interface.

Jump to

Keyboard shortcuts

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