generated from SidingsMedia/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (51 loc) · 1.93 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
54
55
56
57
58
59
60
61
62
63
// SPDX-FileCopyrightText: 2023-2024 Sidings Media
// SPDX-License-Identifier: MIT
package main
import (
"log"
"strings"
"github.com/SidingsMedia/messaging/controller"
"github.com/SidingsMedia/messaging/service"
"github.com/SidingsMedia/messaging/util"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func init() {
log.Println("Fetching environment variables")
// This will fail in a docker container. Perhaps we need to check if
// we are in a container and only run if not.
err := godotenv.Load()
if err != nil {
log.Println("Failed to load .env file")
}
// Server settings
util.BindAddr = util.SGetenv(util.BindAddrEnv, util.DefaultBindAddr)
util.TrustedProxies = strings.Split(
util.SGetenv(util.TrustedProxiesEnv, util.DefaultTrustedProxies),
",",
)
// Ticket server settings
util.TicketAPIURL = util.Mustgetenv(util.TicketAPIURLEnv)
util.TicketHealthURL = util.Mustgetenv(util.TicketHealthURLEnv)
util.TicketAPIKey = util.Mustgetenv(util.TicketAPIKeyEnv)
util.TicketShouldAlert = util.BGetenv(util.TicketShouldAlertEnv, util.DefaultTicketShouldAlert)
util.TicketShouldAutorespond = util.BGetenv(util.TicketShouldAutorespondEnv, util.DefaultTicketShouldAutorespond)
util.TicketSource = util.SGetenv(util.TicketSourceEnv, util.DefaultTicketSource)
}
func main() {
messagingService := service.NewMessagingService()
engine := gin.Default()
engine.Use(cors.Default())
controller.NewMessagingController(engine, messagingService)
// Set trusted proxies. If user has set it to * then we can just
// ignore it as GIN trusts all by default
if util.TrustedProxies[0] != "*" {
if err := engine.SetTrustedProxies(util.TrustedProxies); err != nil {
log.Fatalf("Failed to set trusted proxies. %s", err)
}
log.Printf("Trusting the following proxies: %s", util.TrustedProxies)
}
log.Printf("Starting server on %s\n", util.BindAddr)
engine.Run(util.BindAddr)
}