all repos

onasty @ f4d5d3342ef1bd0a6efb8ebde0b9385a204f4700

a one-time notes service

onasty/mailer/template.go (view raw)

Smirnov Oleksandr Smirnov Oleksandr
ss2316544@gmail.com
feat: mailer service (#55)..., 1 year ago
1
package main
2
3
import (
4
	"errors"
5
	"fmt"
6
)
7
8
type Template struct {
9
	Subject string
10
	Body    string
11
}
12
13
type TemplateFunc func(args map[string]string) Template
14
15
func getTemplate(appURL string, templateName string) (TemplateFunc, error) {
16
	if templateName == "email_verification" {
17
		return emailVerificationTemplate(appURL), nil
18
	}
19
20
	return nil, errors.New("failed to get template") //nolint:err113
21
}
22
23
func emailVerificationTemplate(appURL string) TemplateFunc {
24
	return func(opts map[string]string) Template {
25
		return Template{
26
			Subject: "Onasty: verify your email",
27
			Body: fmt.Sprintf(`To verify your email, please follow this link:
28
<a href="%[1]s/api/v1/auth/verify/%[2]s">%[1]s/api/v1/auth/verify/%[2]s</a>
29
<br />
30
<br />
31
This link will expire after 24 hours.`, appURL, opts["token"]),
32
		}
33
	}
34
}