-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.go
67 lines (53 loc) · 1.27 KB
/
mailer.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"os"
"log"
"mailer/rabbitmq"
"mailer/token"
"mailer/interfaces"
"mailer/handlers"
"mailer/mailers"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Println("Error loading .env file:", err)
}
queueName := "mailer_queue"
conn, err := rabbitmq.ConnectToRabbitMQ()
if err != nil {
log.Fatal(err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {
log.Fatal(err)
}
defer ch.Close()
err = rabbitmq.DeclareQueue(ch, queueName)
if err != nil {
log.Fatal(err)
}
messages, err := rabbitmq.ConsumeMessages(ch, queueName)
if err != nil {
log.Fatal(err)
}
log.Printf("[*] Waiting for messages.")
for msg := range messages {
log.Printf("Received message: %s", msg.Body)
var recordInterfaces interfaces.Record
record := token.DecodeToken(string(msg.Body), &recordInterfaces)
if record != nil {
log.Println(record)
}else{
data, err := handlers.ClaimAllRecordData(string(msg.Body), recordInterfaces.Tag)
if err != nil {
log.Println(err)
}
log.Println("======= Record =======")
log.Println(data)
mailers.SendMail(recordInterfaces, data)
}
}
}