Documentation ¶
Index ¶
- func Execute(template, startTag, endTag string, w io.Writer, m map[string]interface{}) (int64, error)
- func ExecuteFunc(template, startTag, endTag string, w io.Writer, f TagFunc) (int64, error)
- func ExecuteFuncString(template, startTag, endTag string, f TagFunc) string
- func ExecuteFuncStringWithErr(template, startTag, endTag string, f TagFunc) (string, error)
- func ExecuteStd(template, startTag, endTag string, w io.Writer, m map[string]interface{}) (int64, error)
- func ExecuteString(template, startTag, endTag string, m map[string]interface{}) string
- func ExecuteStringStd(template, startTag, endTag string, m map[string]interface{}) string
- type TagFunc
- type Template
- func (t *Template) Execute(w io.Writer, m map[string]interface{}) (int64, error)
- func (t *Template) ExecuteFunc(w io.Writer, f TagFunc) (int64, error)
- func (t *Template) ExecuteFuncString(f TagFunc) string
- func (t *Template) ExecuteFuncStringWithErr(f TagFunc) (string, error)
- func (t *Template) ExecuteStd(w io.Writer, m map[string]interface{}) (int64, error)
- func (t *Template) ExecuteString(m map[string]interface{}) string
- func (t *Template) ExecuteStringStd(m map[string]interface{}) string
- func (t *Template) Reset(template, startTag, endTag string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Execute ¶
func Execute(template, startTag, endTag string, w io.Writer, m map[string]interface{}) (int64, error)
Execute substitutes template tags (placeholders) with the corresponding values from the map m and writes the result to the given writer w.
Substitution map m may contain values with the following types:
- []byte - the fastest value type
- string - convenient value type
- TagFunc - flexible value type
Returns the number of bytes written to w.
This function is optimized for constantly changing templates. Use Template.Execute for frozen templates.
func ExecuteFunc ¶
ExecuteFunc calls f on each template tag (placeholder) occurrence.
Returns the number of bytes written to w.
This function is optimized for constantly changing templates. Use Template.ExecuteFunc for frozen templates.
func ExecuteFuncString ¶
ExecuteFuncString calls f on each template tag (placeholder) occurrence and substitutes it with the data written to TagFunc's w.
Returns the resulting string.
This function is optimized for constantly changing templates. Use Template.ExecuteFuncString for frozen templates.
func ExecuteFuncStringWithErr ¶
ExecuteFuncStringWithErr is nearly the same as ExecuteFuncString but when f returns an error, ExecuteFuncStringWithErr won't panic like ExecuteFuncString it just returns an empty string and the error f returned
func ExecuteStd ¶
func ExecuteStd(template, startTag, endTag string, w io.Writer, m map[string]interface{}) (int64, error)
ExecuteStd works the same way as Execute, but keeps the unknown placeholders. This can be used as a drop-in replacement for strings.Replacer
Substitution map m may contain values with the following types:
- []byte - the fastest value type
- string - convenient value type
- TagFunc - flexible value type
Returns the number of bytes written to w.
This function is optimized for constantly changing templates. Use Template.ExecuteStd for frozen templates.
func ExecuteString ¶
ExecuteString substitutes template tags (placeholders) with the corresponding values from the map m and returns the result.
Substitution map m may contain values with the following types:
- []byte - the fastest value type
- string - convenient value type
- TagFunc - flexible value type
This function is optimized for constantly changing templates. Use Template.ExecuteString for frozen templates.
func ExecuteStringStd ¶
ExecuteStringStd works the same way as ExecuteString, but keeps the unknown placeholders. This can be used as a drop-in replacement for strings.Replacer
Substitution map m may contain values with the following types:
- []byte - the fastest value type
- string - convenient value type
- TagFunc - flexible value type
This function is optimized for constantly changing templates. Use Template.ExecuteStringStd for frozen templates.
Types ¶
type TagFunc ¶
TagFunc can be used as a substitution value in the map passed to Execute*. Execute* functions pass tag (placeholder) name in 'tag' argument.
TagFunc must be safe to call from concurrently running goroutines.
TagFunc must write contents to w and return the number of bytes written.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template implements simple template engine, which can be used for fast tags' (aka placeholders) substitution.
func New ¶
New parses the given template using the given startTag and endTag as tag start and tag end.
The returned template can be executed by concurrently running goroutines using Execute* methods.
New panics if the given template cannot be parsed. Use NewTemplate instead if template may contain errors.
func NewTemplate ¶
NewTemplate parses the given template using the given startTag and endTag as tag start and tag end.
The returned template can be executed by concurrently running goroutines using Execute* methods.
func (*Template) Execute ¶
Execute substitutes template tags (placeholders) with the corresponding values from the map m and writes the result to the given writer w.
Substitution map m may contain values with the following types:
- []byte - the fastest value type
- string - convenient value type
- TagFunc - flexible value type
Returns the number of bytes written to w.
func (*Template) ExecuteFunc ¶
ExecuteFunc calls f on each template tag (placeholder) occurrence.
Returns the number of bytes written to w.
This function is optimized for frozen templates. Use ExecuteFunc for constantly changing templates.
func (*Template) ExecuteFuncString ¶
ExecuteFuncString calls f on each template tag (placeholder) occurrence and substitutes it with the data written to TagFunc's w.
Returns the resulting string.
This function is optimized for frozen templates. Use ExecuteFuncString for constantly changing templates.
func (*Template) ExecuteFuncStringWithErr ¶
ExecuteFuncStringWithErr calls f on each template tag (placeholder) occurrence and substitutes it with the data written to TagFunc's w.
Returns the resulting string.
This function is optimized for frozen templates. Use ExecuteFuncString for constantly changing templates.
func (*Template) ExecuteStd ¶
ExecuteStd works the same way as Execute, but keeps the unknown placeholders. This can be used as a drop-in replacement for strings.Replacer
Substitution map m may contain values with the following types:
- []byte - the fastest value type
- string - convenient value type
- TagFunc - flexible value type
Returns the number of bytes written to w.
func (*Template) ExecuteString ¶
ExecuteString substitutes template tags (placeholders) with the corresponding values from the map m and returns the result.
Substitution map m may contain values with the following types:
- []byte - the fastest value type
- string - convenient value type
- TagFunc - flexible value type
This function is optimized for frozen templates. Use ExecuteString for constantly changing templates.
func (*Template) ExecuteStringStd ¶
ExecuteStringStd works the same way as ExecuteString, but keeps the unknown placeholders. This can be used as a drop-in replacement for strings.Replacer
Substitution map m may contain values with the following types:
- []byte - the fastest value type
- string - convenient value type
- TagFunc - flexible value type
This function is optimized for frozen templates. Use ExecuteStringStd for constantly changing templates.