Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Database type (sqlite or postgres)
Type DatabaseType
// SQLite configuration
DatabasePath string // Path to SQLite database file
// PostgreSQL configuration
Host string
Port string
Username string
Password string
Database string
SSLMode string
// Connection pool settings (applies to both database types)
MaxOpenConns int // Maximum number of open connections
MaxIdleConns int // Maximum number of idle connections
ConnMaxLifetime time.Duration // Maximum amount of time a connection may be reused
ConnMaxIdleTime time.Duration // Maximum amount of time a connection may be idle before being closed
}
Config holds database connection configuration
func NewDatabaseConfig ¶
func NewDatabaseConfig() *Config
NewDatabaseConfig creates a new database configuration from environment variables Supports both SQLite (default) and PostgreSQL databases Configuration priority:
- If DB_TYPE=postgres → PostgreSQL (DB_HOST, DB_PASSWORD, etc. required)
- If DB_TYPE=sqlite OR DB_PATH is set → File-based SQLite (default: ./data/audit.db) Note: Unknown DB_TYPE values also default to file-based SQLite
- If no database configuration (no DB_TYPE, no DB_PATH) → In-memory SQLite (:memory:) Note: DB_HOST is only relevant for PostgreSQL and does not count as "database configuration"
type DatabaseType ¶
type DatabaseType string
DatabaseType represents the type of database to use
const ( DatabaseTypeSQLite DatabaseType = "sqlite" DatabaseTypePostgres DatabaseType = "postgres" )
Click to show internal directories.
Click to hide internal directories.