liveBook · Manning

Pipeline

As explained in Learn Go with Pocket-Sized Projects

A template pipeline is a sequence of template commands in which each command's output becomes input to the next command.

A template pipeline passes each command’s output to the next command as input. Write it with the pipe character: {{ func1 . | func2 }} is equivalent to func2(func1(.)), and pipelines can contain any number of stages. section 11.5.2

Register the functions a template may call with Funcs, then chain those functions where each transformation depends on the previous result. The same value can also be emphasized explicitly: {{ . | len }} and {{ len . }} produce the same length. section 11.5.2

Normalize hostnames

Extract a hostname, lowercase it, and print each result on its own line with {{range .}}{{extractDomainNames . | lower | println}}{{end }}. For URLs including http://UN.org, the output includes un.org. section 11.5.2

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines pipe-based composition and demonstrates function registration, but stops short of deeper execution internals.
Examples
Uses URL hostname extraction, lowercase normalization, println output, and a slice of example URLs.
What it assumes
Assumes familiarity with template actions and functions while making pipeline syntax explicit through a Unix-style analogy.
What you can do after
Apply it in Go templates by registering functions with Funcs and chaining their outputs with |.
How it connects
Connects template functions, range actions, and function registration through Funcs.

Also explained in

Compare how 48 books explain pipeline →

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.