Documentation ¶
Index ¶
- Variables
- type Brain
- type ExecuteInput
- type ExecuteResult
- type NewTemplateInput
- type Scratch
- func (s *Scratch) Get(k string) interface{}
- func (s *Scratch) Key(k string) bool
- func (s *Scratch) MapSet(k, mk string, v interface{}) (string, error)
- func (s *Scratch) MapSetX(k, mk string, v interface{}) (string, error)
- func (s *Scratch) MapValues(k string) ([]interface{}, error)
- func (s *Scratch) Set(k string, v interface{}) string
- func (s *Scratch) SetX(k string, v interface{}) string
- type Template
Constants ¶
This section is empty.
Variables ¶
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'") // ErrMissingReaderFunction is the error returned when the template // configuration is missing a reader function. ErrMissingReaderFunction = errors.New("template: missing a reader function") )
Functions ¶
This section is empty.
Types ¶
type Brain ¶
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 ¶
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 internally.
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 // Config is a copy of the Runner's consul-template configuration. It is // provided to allow for functions that might need to adapt based on certain // configuration values Config *config.Config }
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 // Destination is the file on disk to render/write the template output. Destination 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 // ErrFatal determines whether template errors should cause the process to // exit, or just log and continue. ErrFatal bool // LeftDelim and RightDelim are the template delimiters. LeftDelim string RightDelim string // ExtFuncMap is a map of external functions that this template is // permitted to run. Allows users to add functions to the library // and selectively opaque existing ones. ExtFuncMap template.FuncMap // 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 // Config keeps local reference to config struct Config *config.TemplateConfig // ReaderFunc is called to read in any source file ReaderFunc config.Reader }
NewTemplateInput is used as input when creating the template.
type Scratch ¶
Scratch is a wrapper around a map which is used by the template.
func (*Scratch) MapSetX ¶
MapSetX behaves the same as MapSet, except it will not overwrite the map key if it already exists.
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 its 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) Config ¶ added in v0.28.2
func (t *Template) Config() *config.TemplateConfig
Config returns the template's config
func (*Template) ErrFatal ¶ added in v0.28.0
ErrFatal indicates whether errors in this template should be fatal.
func (*Template) Execute ¶
func (t *Template) Execute(i *ExecuteInput) (*ExecuteResult, error)
Execute evaluates this template in the provided context.