GetMongoConnection() doens't return error in failure state
File code.fbi.h-da.de/danet/gosdn/controller/nucleus/database/mongo-connection.go
.
Function GetMongoConnection()
doesn't return an error if one is found, it just prints it.
Proposed solution:
// GetMongoConnection Retrieves a client to the MongoDB.
func GetMongoConnection() (*mongo.Client, context.Context, context.CancelFunc, error) {
mongoConnection := config.DatabaseConnection
ctx, cancel := context.WithTimeout(context.Background(), connectTimeout*time.Second)
client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoConnection))
if err != nil {
log.Printf("Failed to create client: %v", err)
return client, ctx, cancel, err
}
// Force a connection to verify our connection string
err = client.Ping(ctx, nil)
if err != nil {
log.Printf("Failed to connect to database: %v\n", err)
return client, ctx, cancel, err
}
return client, ctx, cancel, nil
}
This leads to a lot of changes in storage code.