-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinit.go
51 lines (39 loc) · 1.21 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package emaildriver
import (
"errors"
"html/template"
logger "github.com/TykTechnologies/tyk/log"
)
type TykTemplateName string
type EmailMeta struct {
RecipientEmail string
RecipientName string
FromEmail string
FromName string
Subject string
}
var log = logger.Get().WithField("prefix", "email")
var PortalEmailTemplatesHTML *template.Template
var PortalEmailTemplatesTXT *template.Template
var emailBackendCodeError = errors.New("no backend with this code was found")
var driverInitializationError = errors.New("email driver initialization error")
type EmailBackend interface {
Init(map[string]string) error
Send(EmailMeta, interface{}, TykTemplateName, TykTemplateName, string, string) error
}
var EmailBackendCodes = map[string]EmailBackend{
"mandrill": &MandrillEmailBackend{},
"sendgrid": &SendGridEmailBackend{},
"mailgun": &MailgunEmailBackend{},
"amazonses": &AmazonSESEmailBackend{},
"smtp": &SMTPEmailBackend{},
"mock": &MockEmailBackend{},
}
func GetEmailBackend(code string) (EmailBackend, error) {
var thisInterface EmailBackend
var ok bool
if thisInterface, ok = EmailBackendCodes[code]; !ok {
return nil, emailBackendCodeError
}
return thisInterface, nil
}