funcmap

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 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.

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.
  • today and yesterday are UTC days, on purpose. Both truncate the current time to midnight UTC, whatever zone the server runs in. The server's own midnight is no closer to the visitor's day, and it would make a laptop and production disagree. A template that needs the visitor's day corrects for it, as qwertylicious's calendar does with a date key from the browser.
  • 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. The output safety of htmlMinimal and text is only as strong as that package — changes to escaping there affect what these template funcs emit. summary and textOnly return plain strings, so they depend on it only under text/template. markdown does not use it; its safety rests on goldmark's defaults, which omit raw HTML.

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