jobs-monorepo/services/scraper-google/setup-infrastructure/setup-infrastructure.go
Elshimy Ziad Magdy Taha a195d3b8fe google scraper
2025-12-15 10:26:52 +05:00

38 lines
835 B
Go

package setupinfrastructure
import (
"database/sql"
"log"
"github.com/jobs-scraper/internal/pkg/infrastructure"
"github.com/joho/godotenv"
)
func SetupInfrastructure() (*sql.DB, error) {
// Load .env from the scraper-google service directory
if err := godotenv.Load(".local.env"); err != nil {
log.Printf("No .local.env file found: %v, trying .env", err)
if err := godotenv.Load(".env"); err != nil {
log.Println("No .env file found, using system environment variables")
}
}
dbConfig := infrastructure.LoadConfigFromEnv()
db, err := infrastructure.NewConnection(dbConfig)
if err != nil {
log.Fatalf("Error connecting to db: %v", err)
return nil, err
}
err = db.Ping()
if err != nil {
log.Fatal("Error pinging db")
return nil, err
}
log.Println("Successfully connected to db")
return db, err
}