text package provides text processing utilities. It contains subpackages for templates, scanning, and tabular data.
text/template
Data-driven text templates.Template Syntax
Custom Functions
text/scanner
Text tokenization.text/tabwriter
Aligned text output.Practical Examples
Generate Report
Email Template
Format Table
Best Practices
- Cache templates - Parse once, execute many times
- Validate data - Check template data before rendering
- Use Must carefully - Only for templates that must parse
- Handle errors - Check Execute errors
- Use tabwriter - For aligned output
- Escape when needed - For HTML, use html/template