Standard library / text/template

text/template.FuncMap

Maps names to callable functions. Register functions before parsing actions that use them. Expected stdout: 'ADA\n'.

Formal Syntax & Structure

go syntaxgo
type FuncMap map[string]any

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "strings"  "text/template")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  f := template.FuncMap{"upper": strings.ToUpper}  t := template.Must(template.New("greet").Funcs(f).Parse("{{upper .}}"))  check(t.Execute(os.Stdout, "Ada"))  fmt.Println()}
Go Reference