-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (41 loc) · 1.38 KB
/
main.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
52
53
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/dgdraganov/noti-fire/drivers/email"
"github.com/dgdraganov/noti-fire/drivers/slack"
"github.com/dgdraganov/noti-fire/drivers/sms"
"github.com/dgdraganov/noti-fire/internal/dispatch"
"github.com/dgdraganov/noti-fire/internal/notify"
"github.com/dgdraganov/noti-fire/pkg/config"
"github.com/dgdraganov/noti-fire/pkg/consume"
"github.com/dgdraganov/noti-fire/pkg/kafka"
"github.com/dgdraganov/noti-fire/pkg/log"
"go.uber.org/zap/zapcore"
)
func main() {
conf, err := config.NewConsumerConfig()
if err != nil {
panic(fmt.Sprintf("new config: %s", err))
}
logger := log.NewZapLogger(conf.ConsumerName, zapcore.InfoLevel)
reader := kafka.NewKafkaReader(conf.KafkaConsumerConfig)
consumer := consume.NewMessageConsumer(reader)
dispatcher := dispatch.NewNotificationDispatcher(logger)
dispatcher.RegisterDriver("sms", sms.NewSMSDriver())
dispatcher.RegisterDriver("slack", slack.NewSlackDriver())
dispatcher.RegisterDriver("email", email.NewEmailDriver())
notifyer := notify.NewNotifyer(consumer, dispatcher, logger)
ctx, cancel := context.WithCancel(context.Background())
notifyer.Process(ctx)
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
<-sig
logger.Info("shut down signal received")
cancel()
<-time.After(time.Second * 10)
}