feat: implement database connection and configuration management

- Add database configuration with environment variable support
- Support both PostgreSQL and SQLite database drivers
- Implement connection pooling and timeout configuration
- Add automatic database migration system
- Include connection health checks and error handling
- Configure SSL mode and connection parameters
- Add utility functions for environment variable management
This commit is contained in:
Björn Benouarets
2025-09-30 11:44:25 +02:00
parent e8f4bca221
commit 6e817a8bd2
2 changed files with 129 additions and 0 deletions

26
config/database.go Normal file
View File

@@ -0,0 +1,26 @@
package config
import "git.secnex.io/secnex/certman/utils"
// Config holds database configuration
type Config struct {
Host string
Port string
User string
Password string
DBName string
SSLMode string
Driver string // "postgres" or "sqlite"
}
func GetConfig() *Config {
return &Config{
Host: utils.GetEnv("DB_HOST", "localhost"),
Port: utils.GetEnv("DB_PORT", "5432"),
User: utils.GetEnv("DB_USER", "postgres"),
Password: utils.GetEnv("DB_PASSWORD", "password"),
DBName: utils.GetEnv("DB_NAME", "certman"),
SSLMode: utils.GetEnv("DB_SSLMODE", "disable"),
Driver: utils.GetEnv("DB_DRIVER", "postgres"),
}
}