templates

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 15 Imported by: 6 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultFuncs added in v0.0.11

func DefaultFuncs() template.FuncMap

DefaultFuncs returns Notifykit's default template helper functions.

The returned map is a fresh copy and can be modified by callers.

Types

type HTMLTemplate added in v0.2.0

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

HTMLTemplate renders HTML with contextual escaping. Template source and custom functions must be trusted; use ordinary strings for untrusted notification data.

func LoadHTMLSource added in v0.2.0

func LoadHTMLSource(files fs.FS, source string, opts ...Option) (*HTMLTemplate, error)

LoadHTMLSource loads an HTML template from a file or builtin reference.

func ParseHTMLTemplate added in v0.2.0

func ParseHTMLTemplate(name, input string, opts ...Option) (*HTMLTemplate, error)

ParseHTMLTemplate parses an HTML body with the same options as text templates.

func (*HTMLTemplate) Render added in v0.2.0

func (t *HTMLTemplate) Render(data any) ([]byte, error)

type MissingKey

type MissingKey string

MissingKey controls how templates behave when a map key is missing.

const (
	// MissingKeyDefault keeps the default text/template behavior and renders "<no value>".
	MissingKeyDefault MissingKey = "default"
	// MissingKeyZero renders the zero value for the missing key's element type.
	MissingKeyZero MissingKey = "zero"
	// MissingKeyError returns an execution error when a key is missing.
	MissingKeyError MissingKey = "error"
)

type Option

type Option func(*options)

Option customizes template parsing.

func WithDefaultFuncs added in v0.0.11

func WithDefaultFuncs() Option

WithDefaultFuncs enables Notifykit's default template helper functions.

func WithFunc added in v0.0.2

func WithFunc(name string, fn any) Option

WithFunc adds one custom template function.

func WithFuncs added in v0.0.2

func WithFuncs(funcs template.FuncMap) Option

WithFuncs adds custom template functions.

func WithMissingKey

func WithMissingKey(policy MissingKey) Option

WithMissingKey configures the text/template missingkey option.

type Renderer added in v0.2.0

type Renderer interface{ Render(any) ([]byte, error) }

Renderer renders a notification body. Implementations must support concurrent calls.

type StringTemplate

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

StringTemplate wraps a parsed template that renders strings.

func LoadString

func LoadString(path string, opts ...Option) (*StringTemplate, error)

LoadString reads a file and parses it into a StringTemplate.

func LoadStringFromFS

func LoadStringFromFS(tmplFS fs.FS, path string, opts ...Option) (*StringTemplate, error)

LoadStringFromFS reads a file from an fs.FS into a StringTemplate.

func ParseStringTemplate

func ParseStringTemplate(name, input string, opts ...Option) (*StringTemplate, error)

ParseStringTemplate parses a string-rendering template from a string.

func (*StringTemplate) Render

func (t *StringTemplate) Render(data any) (string, error)

Render executes the template with the provided data and returns a string.

type Template

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

Template wraps a parsed template that renders bytes.

func Load

func Load(path string, opts ...Option) (*Template, error)

Load reads and parses a template file.

func LoadFromFS

func LoadFromFS(tmplFS fs.FS, path string, opts ...Option) (*Template, error)

LoadFromFS reads and parses a template from an fs.FS.

func LoadSource

func LoadSource(templateFS fs.FS, source string, opts ...Option) (*Template, error)

LoadSource reads and parses a template from a file path or builtin reference.

func ParseTemplate

func ParseTemplate(name, input string, opts ...Option) (*Template, error)

ParseTemplate parses a byte-rendering template from a string.

func (*Template) Render

func (t *Template) Render(data any) ([]byte, error)

Render executes the template with the provided data and returns bytes.

Jump to

Keyboard shortcuts

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