-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
50 lines (47 loc) · 1.22 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
package main
import (
"fmt"
"rest-gateway/conf"
"rest-gateway/handlers"
"rest-gateway/logger"
"rest-gateway/router"
"time"
)
func initializeLogger() *logger.Logger {
configuration := conf.GetConfig()
ticker := time.NewTicker(1 * time.Second)
for {
select {
case <-ticker.C:
creds := configuration.CONNECTION_TOKEN
username := configuration.ROOT_USER
if configuration.USER_PASS_BASED_AUTH {
username = "$$memphis"
creds = configuration.CONNECTION_TOKEN + "_" + configuration.ROOT_PASSWORD
if !configuration.CLOUD_ENV {
creds = configuration.ROOT_PASSWORD
}
}
l, err := logger.CreateLogger(configuration.MEMPHIS_HOST, username, creds)
if err != nil {
fmt.Printf("Awaiting to establish connection with Memphis - %v\n", err.Error())
} else {
ticker.Stop()
return l
}
}
}
}
func main() {
configuration := conf.GetConfig()
l := initializeLogger()
err := handlers.ListenForUpdates(l)
if err != nil {
panic("Error while listening for updates - " + err.Error())
}
go handlers.CleanConnectionsCache()
app := router.SetupRoutes(l)
l.Noticef("Memphis REST gateway is up and running")
l.Noticef("Version %s", configuration.VERSION)
app.Listen(":" + configuration.HTTP_PORT)
}