-
Notifications
You must be signed in to change notification settings - Fork 13
/
mail.go
47 lines (37 loc) · 1.26 KB
/
mail.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
package registry
import (
"errors"
"fmt"
"github.com/coretrix/hitrix/service/component/mail"
"github.com/latolukasz/beeorm"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
"github.com/sarulabs/di"
)
// MailMandrill Be sure that you registered entity MailTrackerEntity
func MailMandrill() *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.MailMandrill,
Build: func(ctn di.Container) (interface{}, error) {
ormConfig := ctn.Get(service.ORMConfigService).(beeorm.ValidatedRegistry)
entities := ormConfig.GetEntities()
if _, ok := entities["entity.MailTrackerEntity"]; !ok {
return nil, errors.New("you should register MailTrackerEntity")
}
configService := ctn.Get("config").(config.IConfig)
apiKey, ok := configService.String("mandrill.api_key")
if !ok {
panic(fmt.Errorf("mailchimp.api_key is missing"))
}
fromEmail, ok := configService.String("mandrill.default_from_email")
if !ok {
panic(fmt.Errorf("mailchimp.default_from_email is missing"))
}
fromName, ok := configService.String("mandrill.from_name")
if !ok {
panic(fmt.Errorf("mandrill.from_name is missing"))
}
return mail.NewMandrill(apiKey, fromEmail, fromName), nil
},
}
}