wip
This commit is contained in:
@@ -9,14 +9,54 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/timetracker/backend/internal/models"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
// DatabaseConfig contains the configuration data for the database connection
|
||||
type DatabaseConfig struct {
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
DBName string
|
||||
SSLMode string
|
||||
MaxIdleConns int // Maximum number of idle connections
|
||||
MaxOpenConns int // Maximum number of open connections
|
||||
MaxLifetime time.Duration // Maximum lifetime of a connection
|
||||
LogLevel logger.LogLevel
|
||||
}
|
||||
|
||||
// DefaultDatabaseConfig returns a default configuration with sensible values
|
||||
func DefaultDatabaseConfig() DatabaseConfig {
|
||||
return DatabaseConfig{
|
||||
Host: "localhost",
|
||||
Port: 5432,
|
||||
User: "timetracker",
|
||||
Password: "password",
|
||||
DBName: "timetracker",
|
||||
SSLMode: "disable",
|
||||
MaxIdleConns: 10,
|
||||
MaxOpenConns: 100,
|
||||
MaxLifetime: time.Hour,
|
||||
LogLevel: logger.Info,
|
||||
}
|
||||
}
|
||||
|
||||
// JWTConfig represents the configuration for JWT authentication
|
||||
type JWTConfig struct {
|
||||
Secret string
|
||||
TokenDuration time.Duration
|
||||
KeyGenerate bool
|
||||
KeyDir string
|
||||
PrivKeyFile string
|
||||
PubKeyFile string
|
||||
KeyBits int
|
||||
}
|
||||
|
||||
// Config represents the application configuration
|
||||
type Config struct {
|
||||
Database models.DatabaseConfig
|
||||
JWTConfig models.JWTConfig
|
||||
Database DatabaseConfig
|
||||
JWTConfig JWTConfig
|
||||
APIKey string
|
||||
}
|
||||
|
||||
@@ -26,8 +66,8 @@ func LoadConfig() (*Config, error) {
|
||||
_ = godotenv.Load()
|
||||
|
||||
cfg := &Config{
|
||||
Database: models.DefaultDatabaseConfig(),
|
||||
JWTConfig: models.JWTConfig{},
|
||||
Database: DefaultDatabaseConfig(),
|
||||
JWTConfig: JWTConfig{},
|
||||
}
|
||||
|
||||
// Load database configuration
|
||||
|
||||
Reference in New Issue
Block a user