mirror of
https://github.com/HexCardGames/HexDeck.git
synced 2025-09-05 19:18:39 +02:00
fix(backend): make sure database connection was successful before continuing
This commit is contained in:
@ -70,13 +70,22 @@ func (conn *DatabaseConnection) QueryGlobalStats() GlobalStatsCollection {
|
||||
return stats
|
||||
}
|
||||
|
||||
func CreateDBConnection(uri string) DatabaseConnection {
|
||||
client, _ := mongo.Connect(options.Client().ApplyURI(uri))
|
||||
return DatabaseConnection{client}
|
||||
func CreateDBConnection(uri string) *DatabaseConnection {
|
||||
client, err := mongo.Connect(options.Client().ApplyURI(uri))
|
||||
if err != nil {
|
||||
slog.Error("MongoDB connection failed", "error", err)
|
||||
return nil
|
||||
}
|
||||
return &DatabaseConnection{client}
|
||||
}
|
||||
|
||||
var Conn DatabaseConnection
|
||||
|
||||
func InitDB(uri string) {
|
||||
Conn = CreateDBConnection(uri)
|
||||
func InitDB(uri string) bool {
|
||||
dbConn := CreateDBConnection(uri)
|
||||
if dbConn == nil {
|
||||
return false
|
||||
}
|
||||
Conn = *dbConn
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user