mirror of
https://github.com/1f349/tulip.git
synced 2024-12-23 08:44:11 +00:00
28 lines
493 B
Go
28 lines
493 B
Go
package templates
|
|
|
|
import (
|
|
"embed"
|
|
"io"
|
|
"log"
|
|
"text/template"
|
|
)
|
|
|
|
var (
|
|
//go:embed *
|
|
embeddedTemplates embed.FS
|
|
|
|
mailTemplate *template.Template
|
|
)
|
|
|
|
func LoadMailTemplates() (err error) {
|
|
mailTemplate, err = template.New("mail").ParseFS(embeddedTemplates, "*.go.txt")
|
|
return
|
|
}
|
|
|
|
func RenderMailTemplate(wr io.Writer, name string, data any) {
|
|
err := mailTemplate.ExecuteTemplate(wr, name+".go.txt", data)
|
|
if err != nil {
|
|
log.Printf("Failed to render mail: %s: %s\n", name, err)
|
|
}
|
|
}
|