template

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package template provides support for evaluating text templates in Aptomi, with support for caching compiled templates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a thread-safe cache of compiled text templates

func NewCache

func NewCache() *Cache

NewCache creates a new thread-safe Cache

func (*Cache) Evaluate

func (cache *Cache) Evaluate(templateStr string, params *Parameters) (string, error)

Evaluate evaluates text template given a set of parameters. If an compiled text template already exists in cache, it will be used. Otherwise it will get compiled and added to the cache before evaluating the text template. This method is thread-safe and can be called concurrently from multiple goroutines.

type Parameters

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

Parameters is a set of named parameters for the text template

func NewParams

func NewParams(params interface{}) *Parameters

NewParams creates a new instance of Parameters

type Template

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

Template struct contains text template string as well as its compiled version

func NewTemplate

func NewTemplate(templateStr string) (*Template, error)

NewTemplate compiles a text template and returns the result in Template struct Parameter templateStr must follow syntax defined by text/template

func (*Template) Evaluate

func (template *Template) Evaluate(params *Parameters) (string, error)

Evaluate evaluates a compiled text template given a set named parameters

Jump to

Keyboard shortcuts

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