_What is a comprehensive list of built in functions_ Go text templates support pipelines and chaining of actions, which are powerful features that allow you to process data through a series of transformations in a readable, left-to-right manner. ## Pipelines A pipeline in Go templates uses the pipe operator `|` to pass the output of one action as input to the next. The basic syntax is: ``` {{ value | function1 | function2 | function3 }} ``` The value flows from left to right through each function. Here's a simple example: ```go {{ .Name | printf "Hello, %s!" | print }} ``` This takes the `.Name` field, passes it to `printf` to format it, then passes the result to `print`. ## Chaining Actions You can chain multiple template actions together using pipelines. Common patterns include: **String manipulation:** ```go {{ .Title | lower | title }} // Convert to lowercase, then title case {{ .Content | html | printf "

%s

" }} // HTML escape, then wrap in tags ``` **Conditional processing:** ```go {{ .Value | default "N/A" | printf "Result: %s" }} ``` **Multiple transformations:** ```go {{ .Price | printf "%.2f" | printf "$%s" }} // Format as decimal, then add dollar sign ``` ## Built-in Functions in Pipelines Go templates provide several built-in functions that work well in pipelines: - `printf` - Format strings (like `fmt.Sprintf`) - `print`, `println` - Output functions - `html` - HTML escape - `js` - JavaScript escape - `urlquery` - URL query escape - `len` - Length of arrays, slices, maps, strings - `index` - Get element at index - `slice` - Create slice from array/slice ## Custom Functions You can register custom functions for use in pipelines: ```go funcMap := template.FuncMap{ "upper": strings.ToUpper, "reverse": func(s string) string { runes := []rune(s) for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { runes[i], runes[j] = runes[j], runes[i] } return string(runes) }, } tmpl := template.New("example").Funcs(funcMap) ``` Then use them in pipelines: ```go {{ .Name | upper | reverse | printf "Transformed: %s" }} ``` ## Complex Pipeline Examples **Processing lists:** ```go {{ range .Items }} {{ . | printf "Item: %s" | println }} {{ end }} ``` **Conditional formatting:** ```go {{ if .IsActive }} {{ .Status | upper | printf "STATUS: %s" }} {{ else }} {{ "inactive" | printf "STATUS: %s" }} {{ end }} ``` **Nested data access:** ```go {{ .User.Email | printf "mailto:%s" | printf "Contact" | html }} ``` Pipelines make Go templates more readable and allow you to build complex data transformations by composing simple functions. The key is that data flows left-to-right through the pipeline, with each function receiving the output of the previous one as its final argument.