mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
30 lines
568 B
Go
30 lines
568 B
Go
package mail
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
//go:embed out/*.html
|
|
var templates embed.FS
|
|
|
|
func GetMailTemplate(name string) (string, error) {
|
|
data, err := templates.ReadFile(fmt.Sprintf("out/%s.html", name))
|
|
if err != nil {
|
|
return "", fmt.Errorf("mail template %q not found", name)
|
|
}
|
|
return string(data), nil
|
|
}
|
|
|
|
func RenderMailTemplate(name string, vars map[string]string) (string, error) {
|
|
html, err := GetMailTemplate(name)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
for k, v := range vars {
|
|
html = strings.ReplaceAll(html, k, v)
|
|
}
|
|
return html, nil
|
|
}
|