@@ -3,6 +3,7 @@ package services
3
3
import (
4
4
"bytes"
5
5
"crypto/tls"
6
+ "embed"
6
7
"html/template"
7
8
"log"
8
9
"os"
@@ -12,6 +13,9 @@ import (
12
13
"gopkg.in/gomail.v2"
13
14
)
14
15
16
+ //go:embed email_templates
17
+ var staticFS embed.FS
18
+
15
19
type EmailService interface {
16
20
SendTwoFactorRequest (randomCode string , userDetails models.User ) error
17
21
SendEmailLoginRequest (randomCode string , userDetails models.User ) error
@@ -59,7 +63,7 @@ func (emSrv *emailService) sendEmail(to []string, subject, message string) error
59
63
func (emSrv * emailService ) SendTwoFactorRequest (randomCode string , userDetails models.User ) error {
60
64
var twoFactorRequestTemplateBuffer bytes.Buffer
61
65
// Get email template from directory and assign random code to it
62
- emailTemplateFile , err := template .ParseFiles ( "static/ email_templates/TwoFactorLogin.html" )
66
+ emailTemplateFile , err := template .ParseFS ( staticFS , " email_templates/TwoFactorLogin.html" )
63
67
if err != nil {
64
68
return err
65
69
}
@@ -83,7 +87,7 @@ func (emSrv *emailService) SendTwoFactorRequest(randomCode string, userDetails m
83
87
func (emSrv * emailService ) SendEmailLoginRequest (randomCode string , userDetails models.User ) error {
84
88
var twoFactorRequestTemplateBuffer bytes.Buffer
85
89
// Get email template from directory and assign random code to it
86
- emailTemplateFile , err := template .ParseFiles ( "static/ email_templates/EmailLogin.html" )
90
+ emailTemplateFile , err := template .ParseFS ( staticFS , " email_templates/EmailLogin.html" )
87
91
if err != nil {
88
92
return err
89
93
}
@@ -108,7 +112,7 @@ func (emSrv *emailService) SendEmailLoginRequest(randomCode string, userDetails
108
112
func (emSrv * emailService ) SendPasswordResetRequest (randomCode string , userDetails models.User ) error {
109
113
var passwordResetTemplateBuffer bytes.Buffer
110
114
// Get email template from directory and assign random code to it
111
- emailTemplateFile , err := template .ParseFiles ( "static/ email_templates/PasswordRequest.html" )
115
+ emailTemplateFile , err := template .ParseFS ( staticFS , " email_templates/PasswordRequest.html" )
112
116
if err != nil {
113
117
log .Println ("Template reading " , err )
114
118
return err
0 commit comments