templateutil

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 7 Imported by: ? 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 Fields

func Fields(text string) ([]string, error)

Placeholder names of a template in order of first appearance, nested placeholders included

func Format

func Format(text string, values map[string]any) (string, error)

Text of a template with each placeholder replaced by its value in values

Types

type MissingError

type MissingError struct{ Name string }

Placeholder whose name has no value

func (*MissingError) Error

func (e *MissingError) Error() string

The placeholder that has no value

type SpecError

type SpecError struct {
	Name string
	Spec string
	Msg  string
}

Placeholder whose format spec does not suit its value, or does not parse once its nested placeholders are filled in

func (*SpecError) Error

func (e *SpecError) Error() string

The placeholder, its spec and what is wrong with them

type SyntaxError

type SyntaxError struct {
	Offset int
	Msg    string
}

Template text that does not parse, with the byte offset where the problem starts

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

The problem and where it is

type Template

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

Text with {name} and {name:spec} placeholders, parsed once and safe to render from many goroutines

func Parse

func Parse(text string) (*Template, error)

Template parsed from text where {name} and {name:spec} are placeholders and {{ and }} stand for literal braces

func (*Template) Fields

func (t *Template) Fields() []string

Names of the placeholders in order of first appearance, nested placeholders included; shared slice, callers must not modify it

func (*Template) Render

func (t *Template) Render(lookup func(name string) (any, bool)) (string, error)

Text with each placeholder replaced by the value lookup gives for its name, formatted under its spec

Jump to

Keyboard shortcuts

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