add env files
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
aovantsev
2025-10-03 13:33:22 +03:00
parent 324e861218
commit d0f14dfca2
22 changed files with 468 additions and 41 deletions

View File

@@ -11,7 +11,7 @@ import (
var db *sql.DB
// InitDB initializes the database connection
// InitDB initializes the database connection (legacy function)
func InitDB() error {
// Get database URL from environment variable
dbURL := os.Getenv("DATABASE_URL")
@@ -19,6 +19,16 @@ func InitDB() error {
// Default for local development
dbURL = "postgres://postgres:password@localhost:5432/counter_db?sslmode=disable"
}
return initDBWithURL(dbURL)
}
// InitDBWithConfig initializes the database connection with configuration
func InitDBWithConfig(config *Config) error {
return initDBWithURL(config.DatabaseURL)
}
// initDBWithURL initializes the database connection with a specific URL
func initDBWithURL(dbURL string) error {
var err error
db, err = sql.Open("postgres", dbURL)
@@ -31,7 +41,7 @@ func InitDB() error {
return fmt.Errorf("failed to ping database: %w", err)
}
log.Println("Database connection established")
log.Println("Database connection established successfully")
return nil
}
@@ -72,7 +82,7 @@ func CreateTables() error {
}
}
log.Println("Database tables created successfully")
log.Println("Database tables created successfully")
return nil
}