templates

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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 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 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