-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_io.go
More file actions
53 lines (43 loc) · 892 Bytes
/
common_io.go
File metadata and controls
53 lines (43 loc) · 892 Bytes
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 (
"encoding/json"
"fmt"
"log"
"github.com/asvins/auth/models"
"github.com/asvins/common_io"
"github.com/asvins/notification/mailer"
"github.com/asvins/utils/config"
)
func setupCommonIo() {
cfg := common_io.Config{}
err := config.Load("common_io_config.gcfg", &cfg)
if err != nil {
log.Fatal(err)
}
/*
* Producer
*/
producer, err = common_io.NewProducer(cfg)
if err != nil {
log.Fatal(err)
}
}
/*
* Senders
*/
func sendUserCreated(usr *models.User) {
topic, _ := common_io.BuildTopicFromCommonEvent(common_io.EVENT_CREATED, "user")
b, err := json.Marshal(usr)
if err != nil {
fmt.Println("[ERROR] ", err.Error())
return
}
m := mailer.Mail{
To: []string{usr.Email},
Subject: "Bem Vindo!",
Body: mailer.TemplateWelcome,
}
mMsg, _ := json.Marshal(m)
producer.Publish("send_mail", mMsg)
producer.Publish(topic, b)
}