Documentation
¶
Index ¶
- Constants
- func Execute(tmpl *template.Template, data any) (string, error)
- func FuncMap() template.FuncMap
- func IsBuiltin(source string) bool
- func Name(source string) string
- func Parse(name, value string, opts ...Option) (*template.Template, error)
- func ParseSource(templateFS fs.FS, source string, opts ...Option) (*template.Template, error)
- func ReadSource(templateFS fs.FS, source string) (name string, body string, err error)
- type MissingKey
- type Option
- type StringTemplate
- type Template
- type Templates
Constants ¶
const (
// BuiltinPrefix marks a template source as an embedded built-in template.
BuiltinPrefix = "builtin:"
)
Variables ¶
This section is empty.
Functions ¶
func ParseSource ¶
ParseSource reads and parses a template from a file path or builtin reference.
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 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 ¶
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.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template wraps a parsed template that renders bytes.
func LoadFromFS ¶
LoadFromFS reads and parses a template from an fs.FS.
func LoadSource ¶
LoadSource reads and parses a template from a file path or builtin reference.
func ParseTemplate ¶
ParseTemplate parses a byte-rendering template from a string.
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
Templates reads built-in templates from an injected filesystem.
func New ¶
New creates a built-in template registry backed by files.
The returned registry is used for builtin: template sources. A nil filesystem is allowed, but Read and Exists will return an error and Names will return nil.