-
Notifications
You must be signed in to change notification settings - Fork 14
/
mail.go
46 lines (36 loc) · 1.21 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
package registry
import (
"fmt"
"github.com/coretrix/hitrix/pkg/entity"
"github.com/coretrix/hitrix/service/component/mail"
"github.com/latolukasz/orm"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
"github.com/sarulabs/di"
)
func MailMandrill() *service.Definition {
ORMRegistryContainer = append(ORMRegistryContainer, func(registry *orm.Registry) {
registry.RegisterEntity(&entity.MailTrackerEntity{})
registry.RegisterEnumStruct("entity.MailTrackerStatusAll", entity.MailTrackerStatusAll)
})
return &service.Definition{
Name: service.MailMandrill,
Global: true,
Build: func(ctn di.Container) (interface{}, error) {
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
},
}
}