liveBook · Manning

Funcs

As explained in Learn Go with Pocket-Sized Projects

Funcs is a Go template method that registers named functions available to template actions.

Funcs registers named Go functions for use in template actions. Pass a template.FuncMap when creating the template; map keys become template identifiers and values provide the Go functions they call. section 11.5.2 section 11.6

Classifying habit progress

A statusCSSClass function maps a habit’s completed fraction to labels such as not_started, started, good_progress, and completed. Register it under that name, then invoke {{ statusCSSClass . }} inside a range to generate a CSS class.

Registered functions can also participate in pipelines:

  • Register extractDomainNames and lower, then pass each result through extractDomainNames | lower | println. section 11.5.2

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains FuncMap registration, template invocation, and pipelines, but stops short of API internals.
Examples
Demonstrates habit-progress CSS labels and URL hostname extraction followed by lowercase normalization.
What you can do after
Apply it via Go templates to register functions, invoke them in actions, and compose results through pipelines.
How it connects
Connects Funcs with Go templates, template actions, FuncMap, ranges, and pipelines.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.