feat: the mail module can use html template directly#1145
feat: the mail module can use html template directly#1145krishankumar01 merged 21 commits intomasterfrom
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 43434ab | Previous: e770490 | Ratio |
|---|---|---|---|
BenchmarkFile_ReadWrite |
304402 ns/op 6258 B/op 99 allocs/op |
180514 ns/op 6257 B/op 99 allocs/op |
1.69 |
BenchmarkFile_ReadWrite - ns/op |
304402 ns/op |
180514 ns/op |
1.69 |
This comment was automatically generated by workflow using github-action-benchmark.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1145 +/- ##
==========================================
+ Coverage 68.44% 68.52% +0.08%
==========================================
Files 221 223 +2
Lines 14320 14466 +146
==========================================
+ Hits 9801 9913 +112
- Misses 4144 4178 +34
Partials 375 375 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hwbrzzl
left a comment
There was a problem hiding this comment.
Awesome. Please add the sent mail screenshots in the description.
There was a problem hiding this comment.
Pull Request Overview
This PR adds configurable template engine support to the mail module, enabling users to render email templates using HTML templates with automatic caching and thread-safe access. The implementation introduces a flexible template engine system that supports both built-in HTML templating and custom template engines via factory functions.
- Introduces a new
Templateinterface and HTML template engine implementation with caching - Adds template registry system for managing multiple template engines with global caching
- Refactors mail job handling to use a single
Paramsstruct instead of multiple individual arguments
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/mail/template.go | Defines the Template interface for rendering templates |
| contracts/mail/mail.go | Extends Content struct to support template views and data |
| mail/template/html.go | Implements HTML template engine with thread-safe caching |
| mail/template/registry.go | Provides global template engine registry with factory support |
| mail/application.go | Integrates template rendering and refactors to use Params struct |
| mail/job.go | Simplifies job arguments to use single Params struct |
| mail/setup/config/mail.go | Adds template configuration options |
| errors/list.go | Adds mail template-specific error types |
| mocks/mail/Template.go | Generated mock for Template interface |
hwbrzzl
left a comment
There was a problem hiding this comment.
Thanks, great 👍 Could you update the description according to the latest logic?
I have already updated the description |
There was a problem hiding this comment.
Pull Request Overview
This PR adds configurable HTML template engine support to the mail module, enabling users to render email templates using Go's html/template engine with built-in caching and thread-safe access. The implementation introduces a template registry system that supports both built-in HTML templates and custom template engines via factory functions.
Key changes include:
- Introduction of a template engine interface and HTML implementation with caching
- Breaking change to
mail.NewApplicationsignature to return an error for template initialization - Extension of mail content structure to support view templates with data binding
- Updated job handling to accommodate separate HTML and text content
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/mail/template.go | Defines the Template interface for rendering templates |
| mail/template/html.go | Implements HTML template engine with caching and thread-safe access |
| mail/template/registry.go | Provides global template engine registry with factory support |
| mail/application.go | Updates mail application to integrate template rendering with breaking API changes |
| mail/job.go | Modifies job handler to support separate HTML/text content parameters |
| mail/setup/config/mail.go | Adds template configuration section with HTML engine defaults |
| errors/list.go | Adds mail template-specific error definitions |
|
|
||
| r.cache.LoadOrStore(templatePath, tmpl) | ||
| return tmpl, nil | ||
| actual, _ := r.cache.LoadOrStore(templatePath, tmpl) |
There was a problem hiding this comment.
Please judge the error here.
There was a problem hiding this comment.
The second parameter is not an error, but a boolean indicating whether the template was loaded successfully. Here, we are storing a new template, so the actual value always presents.
// LoadOrStore returns the existing value for the key if present.
// Otherwise, it stores and returns the given value.
// The loaded result is true if the value was loaded, false if stored.
There was a problem hiding this comment.
Thanks for the explanation.

📑 Description
Closes goravel/goravel#260
Preview
This PR adds configurable template engine support to the mail module, allowing users to render email templates using Go's
html/templateengine with automatic caching and thread-safe access.Features
Usage
Configuration
Email Templates
Create template files in your views directory:
Sending with Templates
Custom Template Engines
Register custom engines in configuration:
Breaking Changes
Yes -
mail.NewApplicationreturns error✅ Checks