Project

General

Profile

Email Notification Service » History » Version 1

karnake ruengchaicharnkij, 04/09/2026 02:28 AM

1 1 karnake ruengchaicharnkij
# Email Notification Service
2
3
``` go
4
package test
5
6
import (
7
	"bytes"
8
	"fmt"
9
	"html/template"
10
	"path/filepath"
11
)
12
13
// RenderHTML renders notification.html with the provided data.
14
func (d NotificationTemplateData) RenderHTML(templatePath string) (string, error) {
15
	if templatePath == "" {
16
		return "", fmt.Errorf("template path is required")
17
	}
18
19
	tmpl, err := template.ParseFiles(templatePath)
20
	if err != nil {
21
		return "", fmt.Errorf("parse template: %w", err)
22
	}
23
24
	var buf bytes.Buffer
25
	templateName := filepath.Base(templatePath)
26
	if err := tmpl.ExecuteTemplate(&buf, templateName, d); err != nil {
27
		return "", fmt.Errorf("render template: %w", err)
28
	}
29
30
	return buf.String(), nil
31
}
32
33
```