-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (39 loc) · 1.5 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
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"github.com/xRebellion/MessageDistributor/integration"
integrationImpl "github.com/xRebellion/MessageDistributor/integration/implementation"
"github.com/xRebellion/MessageDistributor/message"
"github.com/xRebellion/MessageDistributor/recipient"
"github.com/xRebellion/MessageDistributor/router"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func main() {
bgctx := context.Background()
dbClient, err := mongo.Connect(bgctx, options.Client().ApplyURI("mongodb://localhost:27017"))
if err != nil {
panic(err)
}
db := dbClient.Database("MessageDistributor")
discordHttpClient := http.Client{}
integrationRegistry := map[string]integration.Integration{
"email": integrationImpl.EmailInit(os.Getenv("MAILJET_API_KEY"), os.Getenv("MAILJET_SECRET")),
"discord": integrationImpl.DiscordInit("http://localhost:7070", discordHttpClient),
"telegram": integrationImpl.TelegramInit(os.Getenv("TELEGRAM_SECRET"), db.Collection("telegramChatID")),
}
recipientService := recipient.NewService(integrationRegistry, db.Collection("recipients"))
recipientController := recipient.NewController(recipientService)
messageService := message.NewService(integrationRegistry)
messageController := message.NewController(messageService)
router := router.NewChiRouter(
recipientController,
messageController,
).InitRouter()
fmt.Printf("Running at localhost:8080\n\n")
log.Fatal(http.ListenAndServe("localhost:8080", router))
}