Skip to content

Commit d4f35ce

Browse files
committed
embed mail template and store in Application struct
1 parent 6a2d3c6 commit d4f35ce

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

app/app.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package app
33
var app *Application
44

55
type Application struct {
6-
Name string
7-
Version string
8-
Author string
9-
Description string
6+
Name string
7+
Version string
8+
Author string
9+
Description string
10+
MailTemplate string
1011
}
1112

1213
func new() *Application {

app/handler/update/mail.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package update
33
import (
44
_ "embed"
55
"fmt"
6-
"io"
7-
"net/http"
8-
96
"github.com/XotoX1337/tinymail"
107
"github.com/gofiber/fiber/v2"
118
"github.com/gofiber/fiber/v2/log"
@@ -57,17 +54,6 @@ func Mail(c *fiber.Ctx) error {
5754
return err
5855
}
5956

60-
resp, err := http.Get(c.BaseURL() + "/html/mail/update.html")
61-
if err != nil {
62-
fmt.Println(err)
63-
}
64-
defer resp.Body.Close()
65-
66-
body, err := io.ReadAll(resp.Body)
67-
if err != nil {
68-
log.Error(err)
69-
}
70-
7157
tplData := map[string]interface{}{
7258
"Update": update,
7359
"Machine": machine,
@@ -76,7 +62,7 @@ func Mail(c *fiber.Ctx) error {
7662
"App": patchouli.GetApp().Name,
7763
}
7864

79-
msg, err := tinymail.FromTemplateString(tplData, string(body))
65+
msg, err := tinymail.FromTemplateString(tplData, patchouli.GetApp().MailTemplate)
8066
if err != nil {
8167
log.Error(err)
8268
}

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ var views embed.FS
3030
//go:embed public
3131
var public embed.FS
3232

33+
//go:embed public/html/mail/update.html
34+
var mailTemplate string
35+
3336
func main() {
3437
App := patchouli.GetApp()
38+
App.MailTemplate = mailTemplate
3539
engine := html.NewFileSystem(http.FS(views), ".html")
3640
engine.AddFunc("Name", func() string {
3741
return App.Name

0 commit comments

Comments
 (0)