How to use text template package

Import text/template, parse a template string with placeholders, and execute it with a data map to generate dynamic text.

Use the text/template package by importing it, parsing a template string, and executing it with data.

package main

import (
	"os"
	"text/template"
)

func main() {
	tmpl, err := template.New("example").Parse("Hello, {{.Name}}!")
	if err != nil {
		panic(err)
	}
	err = tmpl.Execute(os.Stdout, map[string]string{"Name": "World"})
	if err != nil {
		panic(err)
	}
}