template

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package template provides package-agnostic text template rendering.

It uses Go's standard text/template syntax and never executes rendered text as a command. The renderer returns plain text; it does not HTML-escape output.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrParse identifies invalid template syntax or an unknown template function.
	ErrParse = errors.New("template parse error")
	// ErrExecute identifies a failure while evaluating a parsed template,
	// including a reference to a missing map key.
	ErrExecute = errors.New("template execution error")
)

Functions

func Render

func Render(source string, variables map[string]any) (string, error)

Render evaluates source with variables as the template's root data.

Templates use Go text/template syntax, for example `Hello {{.name}}`. A missing map key is an error (rather than silently rendering an empty value). Extra keys in variables are allowed and ignored when unused. A nil variables map behaves like an empty map. On any error, Render returns an empty string, never partial output.

Values are inserted as text and are not parsed again as template source. Render does not execute shell commands and does not HTML-escape its result.

Example
got, err := Render("Hello {{.name}} — {{.literal}}", map[string]any{
	"name":    "srcpack",
	"literal": "$(this remains text)",
})
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(got)
Output:
Hello srcpack — $(this remains text)

Types

This section is empty.

Jump to

Keyboard shortcuts

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