-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
42 lines (35 loc) · 872 Bytes
/
api.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
package api
import (
"context"
"github.com/google/wire"
"github.com/zldongly/email_server/app/job/internal/service"
"go.uber.org/zap"
)
var ProviderSet = wire.NewSet(NewJob)
type Job interface {
SendEmail(ctx context.Context, e *Email) error
}
// Email from kafka msg.value
type Email struct {
Receivers []string `json:"receivers"`
TemplateId string `json:"template_id"`
Param map[string]string `json:"param"`
}
func NewJob(uc *service.MessageUseCase, log *zap.SugaredLogger) Job {
return &instance{
log: log.With("module", "api"),
uc: uc,
}
}
type instance struct {
log *zap.SugaredLogger
uc *service.MessageUseCase
}
func (i *instance) SendEmail(ctx context.Context, e *Email) error {
m := &service.Mail{
Receivers: e.Receivers,
TemplateId: e.TemplateId,
Param: e.Param,
}
return i.uc.SendMail(ctx, m)
}