template

package
v0.0.0-...-77c115d Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTemplateContentsAndSource is the error returned when a template
	// specifies both a "source" and "content" argument, which is not valid.
	ErrTemplateContentsAndSource = errors.New("template: cannot specify both 'source' and 'contents'")

	// ErrTemplateMissingContentsAndSource is the error returned when a template
	// does not specify either a "source" or "content" argument, which is not
	// valid.
	ErrTemplateMissingContentsAndSource = errors.New("template: must specify exactly one of 'source' or 'contents'")
)

Functions

This section is empty.

Types

type Brain

type Brain struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Brain is what Template uses to determine the values that are available for template parsing.

func NewBrain

func NewBrain() *Brain

NewBrain creates a new Brain with empty values for each of the key structs.

func (*Brain) ForceSet

func (b *Brain) ForceSet(hashCode string, data interface{})

ForceSet is used to force set the value of a dependency for a given hash code

func (*Brain) Forget

func (b *Brain) Forget(d dep.Dependency)

Forget accepts a dependency and removes all associated data with this dependency. It also resets the "receivedData" internal map.

func (*Brain) Recall

func (b *Brain) Recall(d dep.Dependency) (interface{}, bool)

Recall gets the current value for the given dependency in the Brain.

func (*Brain) Remember

func (b *Brain) Remember(d dep.Dependency, data interface{})

Remember accepts a dependency and the data to store associated with that dep. This function converts the given data to a proper type and stores it interally.

type ExecuteInput

type ExecuteInput struct {
	// Brain is the brain where data for the template is stored.
	Brain *Brain

	// Env is a custom environment provided to the template for envvar resolution.
	// Values specified here will take precedence over any values in the
	// environment when using the `env` function.
	Env []string
}

ExecuteInput is used as input to the template's execute function.

type ExecuteResult

type ExecuteResult struct {
	// Used is the set of dependencies that were used.
	Used *dep.Set

	// Missing is the set of dependencies that were missing.
	Missing *dep.Set

	// Output is the rendered result.
	Output []byte
}

ExecuteResult is the result of the template execution.

type NewTemplateInput

type NewTemplateInput struct {
	// Source is the location on disk to the file.
	Source string

	// Contents are the raw template contents.
	Contents string

	// ErrMissingKey causes the template parser to exit immediately with an error
	// when a map is indexed with a key that does not exist.
	ErrMissingKey bool

	// LeftDelim and RightDelim are the template delimiters.
	LeftDelim  string
	RightDelim string

	// FunctionDenylist are functions not permitted to be executed
	// when we render this template
	FunctionDenylist []string

	// SandboxPath adds a prefix to any path provided to the `file` function
	// and causes an error if a relative path tries to traverse outside that
	// prefix.
	SandboxPath string
}

NewTemplateInput is used as input when creating the template.

type Scratch

type Scratch struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Scratch is a wrapper around a map which is used by the template.

func (*Scratch) Get

func (s *Scratch) Get(k string) interface{}

Get returns a value previously set by Add or Set

func (*Scratch) Key

func (s *Scratch) Key(k string) bool

Key returns a boolean indicating whether the given key exists in the map.

func (*Scratch) MapSet

func (s *Scratch) MapSet(k, mk string, v interface{}) (string, error)

MapSet stores the value v into a key mk in the map named k.

func (*Scratch) MapSetX

func (s *Scratch) MapSetX(k, mk string, v interface{}) (string, error)

MapSetX behaves the same as MapSet, except it will not overwrite the map key if it already exists.

func (*Scratch) MapValues

func (s *Scratch) MapValues(k string) ([]interface{}, error)

MapValues returns the list of values in the map sorted by key.

func (*Scratch) Set

func (s *Scratch) Set(k string, v interface{}) string

Set stores the value v at the key k. It will overwrite an existing value if present.

func (*Scratch) SetX

func (s *Scratch) SetX(k string, v interface{}) string

SetX behaves the same as Set, except it will not overwrite existing keys if already present.

type Template

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

Template is the internal representation of an individual template to process. The template retains the relationship between it's contents and is responsible for it's own execution.

func NewTemplate

func NewTemplate(i *NewTemplateInput) (*Template, error)

NewTemplate creates and parses a new Consul Template template at the given path. If the template does not exist, an error is returned. During initialization, the template is read and is parsed for dependencies. Any errors that occur are returned.

func (*Template) Contents

func (t *Template) Contents() string

Contents returns the raw contents of the template.

func (*Template) Execute

func (t *Template) Execute(i *ExecuteInput) (*ExecuteResult, error)

Execute evaluates this template in the provided context.

func (*Template) ID

func (t *Template) ID() string

ID returns the identifier for this template.

func (*Template) Source

func (t *Template) Source() string

Source returns the filepath source of this template.

Jump to

Keyboard shortcuts

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