mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
- Added configuration initialization in db.go to ensure proper setup of application settings. - Refactored runner_test.go to streamline IPC message handling by introducing a setupPipe function and an initRunner function for better readability and maintainability. - Improved synchronization in tests by using channels for signaling readiness and processing, enhancing the reliability of IPC message handling. - Updated test cases to validate IPC message processing and error handling, ensuring robustness in the task runner's functionality.
29 lines
520 B
Go
29 lines
520 B
Go
package mongo
|
|
|
|
import (
|
|
"github.com/crawlab-team/crawlab/core/config"
|
|
"github.com/spf13/viper"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
func init() {
|
|
config.InitConfig()
|
|
}
|
|
|
|
func GetMongoDb(dbName string) *mongo.Database {
|
|
// Use default database name if not provided
|
|
if dbName == "" {
|
|
if dbName = viper.GetString("mongo.db"); dbName == "" {
|
|
dbName = "test"
|
|
}
|
|
}
|
|
|
|
c, err := GetMongoClient()
|
|
if err != nil {
|
|
logger.Errorf("error getting mongo client: %v", err)
|
|
return nil
|
|
}
|
|
|
|
return c.Database(dbName)
|
|
}
|