Skip to content

Commit

Permalink
Fixes service Db dependency on launch time (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
petruki authored Oct 26, 2024
1 parent d3df545 commit 0c4f6f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/db/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func InitDb() *mongo.Database {
err = client.Ping(context.Background(), nil)
if err != nil {
utils.LogError("Error connecting to MongoDB: %s", err.Error())
return nil
}

utils.LogInfo("Connected to MongoDB!")
Expand Down
19 changes: 13 additions & 6 deletions src/server/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,26 @@ func startServerWithSsl(routerHandlers *mux.Router) *http.Server {
}

func initRoutes(db *mongo.Database, coreHandler *core.CoreHandler) *mux.Router {
accountRepository := repository.NewAccountRepositoryMongo(db)
r := mux.NewRouter()

apiController := controller.NewApiController(coreHandler)
accountController := controller.NewAccountController(accountRepository, coreHandler)

r := mux.NewRouter()
apiController.RegisterRoutes(r)
accountController.RegisterRoutes(r)

if db != nil {
accountRepository := repository.NewAccountRepositoryMongo(db)
accountController := controller.NewAccountController(accountRepository, coreHandler)
accountController.RegisterRoutes(r)
}

return r
}

func initCoreHandler(db *mongo.Database) *core.CoreHandler {
var coreHandler *core.CoreHandler
if db == nil {
return core.NewCoreHandler(nil, nil, nil)
}

accountRepository := repository.NewAccountRepositoryMongo(db)
comparatorService := core.NewComparatorService()
apiService := core.NewApiService(
Expand All @@ -118,7 +125,7 @@ func initCoreHandler(db *mongo.Database) *core.CoreHandler {
config.GetEnv("SWITCHER_API_CA_CERT"),
)

coreHandler := core.NewCoreHandler(accountRepository, apiService, comparatorService)
coreHandler = core.NewCoreHandler(accountRepository, apiService, comparatorService)
coreHandler.InitCoreHandlerGoroutine()

return coreHandler
Expand Down

0 comments on commit 0c4f6f9

Please sign in to comment.