diff options
author | Emiliano Ciavatta | 2020-04-21 10:57:10 +0000 |
---|---|---|
committer | Emiliano Ciavatta | 2020-04-21 10:57:10 +0000 |
commit | 516712f670803979c65fd3db73dd2de9d7175139 (patch) | |
tree | 44e701aee56031ea3a731352bd639ae1b060f83c /caronte.go | |
parent | 324623884309e95f541f285faee48150988ec466 (diff) |
Add application_context
Diffstat (limited to 'caronte.go')
-rw-r--r-- | caronte.go | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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") } } |