aboutsummaryrefslogtreecommitdiff
path: root/caronte.go
blob: 288563ce56f0aa746e2630aa5d490ab7dfd379f8 (plain) (blame)
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
package main

import (
	"flag"
	"fmt"
	log "github.com/sirupsen/logrus"
	"io/ioutil"
)

func main() {
	mongoHost := flag.String("mongo-host", "localhost", "address of MongoDB")
	mongoPort := flag.Int("mongo-port", 27017, "port of MongoDB")
	dbName := flag.String("db-name", "caronte", "name of database to use")

	bindAddress := flag.String("bind-address", "0.0.0.0", "address where server is bind")
	bindPort := flag.Int("bind-port", 3333, "port where server is bind")

	flag.Parse()

	logFields := log.Fields{"host": *mongoHost, "port": *mongoPort, "dbName": *dbName}
	storage, err := NewMongoStorage(*mongoHost, *mongoPort, *dbName)
	if err != nil {
		log.WithError(err).WithFields(logFields).Fatal("failed to connect to MongoDB")
	}

	versionBytes, err := ioutil.ReadFile("VERSION")
	if err != nil {
		log.WithError(err).Fatal("failed to load version file")
	}

	applicationContext, err := CreateApplicationContext(storage, string(versionBytes))
	if err != nil {
		log.WithError(err).WithFields(logFields).Fatal("failed to create application context")
	}

	notificationController := NewNotificationController(applicationContext)
	go notificationController.Run()
	applicationRouter := CreateApplicationRouter(applicationContext, notificationController)
	if applicationRouter.Run(fmt.Sprintf("%s:%v", *bindAddress, *bindPort)) != nil {
		log.WithError(err).WithFields(logFields).Fatal("failed to create the server")
	}
}