aboutsummaryrefslogtreecommitdiff
path: root/caronte.go
diff options
context:
space:
mode:
authorEmiliano Ciavatta2020-04-21 10:57:10 +0000
committerEmiliano Ciavatta2020-04-21 10:57:10 +0000
commit516712f670803979c65fd3db73dd2de9d7175139 (patch)
tree44e701aee56031ea3a731352bd639ae1b060f83c /caronte.go
parent324623884309e95f541f285faee48150988ec466 (diff)
Add application_context
Diffstat (limited to 'caronte.go')
-rw-r--r--caronte.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/caronte.go b/caronte.go
index f65247a..d365143 100644
--- a/caronte.go
+++ b/caronte.go
@@ -1,9 +1,9 @@
package main
import (
+ "context"
"flag"
"fmt"
- "github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
@@ -17,17 +17,19 @@ func main() {
flag.Parse()
+ logFields := log.Fields{"host": *mongoHost, "port": *mongoPort, "dbName": *dbName}
storage := NewMongoStorage(*mongoHost, *mongoPort, *dbName)
- err := storage.Connect(nil)
- if err != nil {
- log.WithError(err).Fatal("failed to connect to MongoDB")
+ if err := storage.Connect(context.Background()); err != nil {
+ log.WithError(err).WithFields(logFields).Fatal("failed to connect to MongoDB")
}
- rulesManager := NewRulesManager(storage)
- router := gin.Default()
- ApplicationRoutes(router, rulesManager)
- err = router.Run(fmt.Sprintf("%s:%v", *bindAddress, *bindPort))
+ applicationContext, err := CreateApplicationContext(storage)
if err != nil {
- log.WithError(err).Fatal("failed to create the server")
+ log.WithError(err).WithFields(logFields).Fatal("failed to create application context")
+ }
+
+ applicationRouter := CreateApplicationRouter(applicationContext)
+ if applicationRouter.Run(fmt.Sprintf("%s:%v", *bindAddress, *bindPort)) != nil {
+ log.WithError(err).WithFields(logFields).Fatal("failed to create the server")
}
}