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:
26
config/database.go
Normal file
26
config/database.go
Normal 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"),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user