Text templates
Context
Section titled “Context”The text/template package generates textual output from data using a template syntax. It is safe for HTML generation as well (use html/template for web).
Example
Section titled “Example”Execute a template with struct data.
Code example
Section titled “Code example”package main
import ( "os" "text/template")
func main() { type Person struct { Name string Age int } p := Person{"Alice", 30}
tmpl := template.Must(template.New("greeting").Parse("Hello {{.Name}}, you are {{.Age}} years old.")) tmpl.Execute(os.Stdout, p)}Output
Section titled “Output”Hello Alice, you are 30 years old.