funcmap

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

funcmap

A registry of helper functions for Go text/template / html/template. All() returns a map[string]any (a template.FuncMap) covering compare, arrays, date, currency, HTML, math, logic, and string helpers. Part of rosetta.

Wire it in with template.New("…").Funcs(funcmap.All()).

What matters here

  • Template functions report-and-swallow their errors; they do not return them. Go template functions that return an error abort rendering, so helpers like json, jsonIndent, and markdown instead call derp.Report(...) on failure and return an empty/safe string. This is deliberate — a single bad value should not blow up a whole page render. Don't "fix" these to return errors.
  • All() rebuilds the map on every call. It is meant to be called once at template-parse time, not per-request in a hot path. Each call allocates a fresh map and re-registers every category.
  • HTML-producing helpers depend on the html package's escaping/sanitizing. Output safety (e.g. markdown, the HTML helpers) is only as strong as that package — changes to escaping there affect what these template funcs emit.

Documentation

Overview

Package funcmap provides a registry of helper functions for Go templates.

All returns a map[string]any suitable for passing to Template.Funcs, covering comparison, arrays, dates, currency, HTML, math, logic, and string helpers. It rebuilds that map on every call, so call it once when templates are parsed rather than once per request.

These helpers report their errors rather than returning them. A template function that returns a non-nil error aborts the whole render, so a helper that fails logs through derp and yields an empty or otherwise safe value instead — one bad field should not cost the reader the entire page.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All() map[string]any

All returns a map of every template function provided by this package, keyed by name.

Types

This section is empty.

Jump to

Keyboard shortcuts

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