97 lines
2.2 KiB
Go
97 lines
2.2 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
// Config holds all application configuration
|
|
type Config struct {
|
|
Server ServerConfig
|
|
Database DatabaseConfig
|
|
JWT JWTConfig
|
|
Security SecurityConfig
|
|
App AppConfig
|
|
}
|
|
|
|
// AppConfig holds application-level settings
|
|
type AppConfig struct {
|
|
Environment string // "development" or "production"
|
|
BaseDomain string // "localhost" or "aggios.app"
|
|
}
|
|
|
|
// ServerConfig holds server-specific configuration
|
|
type ServerConfig struct {
|
|
Port string
|
|
}
|
|
|
|
// DatabaseConfig holds database connection settings
|
|
type DatabaseConfig struct {
|
|
Host string
|
|
Port string
|
|
User string
|
|
Password string
|
|
Name string
|
|
}
|
|
|
|
// JWTConfig holds JWT configuration
|
|
type JWTConfig struct {
|
|
Secret string
|
|
}
|
|
|
|
// SecurityConfig holds security settings
|
|
type SecurityConfig struct {
|
|
AllowedOrigins []string
|
|
MaxAttemptsPerMin int
|
|
PasswordMinLength int
|
|
}
|
|
|
|
// Load loads configuration from environment variables
|
|
func Load() *Config {
|
|
env := getEnvOrDefault("APP_ENV", "development")
|
|
baseDomain := "localhost"
|
|
if env == "production" {
|
|
baseDomain = "aggios.app"
|
|
}
|
|
|
|
return &Config{
|
|
Server: ServerConfig{
|
|
Port: getEnvOrDefault("SERVER_PORT", "8080"),
|
|
},
|
|
Database: DatabaseConfig{
|
|
Host: getEnvOrDefault("DB_HOST", "localhost"),
|
|
Port: getEnvOrDefault("DB_PORT", "5432"),
|
|
User: getEnvOrDefault("DB_USER", "postgres"),
|
|
Password: getEnvOrDefault("DB_PASSWORD", "postgres"),
|
|
Name: getEnvOrDefault("DB_NAME", "aggios"),
|
|
},
|
|
JWT: JWTConfig{
|
|
Secret: getEnvOrDefault("JWT_SECRET", "INSECURE-fallback-secret-CHANGE-THIS"),
|
|
},
|
|
App: AppConfig{
|
|
Environment: env,
|
|
BaseDomain: baseDomain,
|
|
},
|
|
Security: SecurityConfig{
|
|
AllowedOrigins: []string{
|
|
"http://localhost",
|
|
"http://dash.localhost",
|
|
"http://aggios.local",
|
|
"http://dash.aggios.local",
|
|
"https://aggios.app",
|
|
"https://dash.aggios.app",
|
|
"https://www.aggios.app",
|
|
},
|
|
MaxAttemptsPerMin: 5,
|
|
PasswordMinLength: 8,
|
|
},
|
|
}
|
|
}
|
|
|
|
// getEnvOrDefault returns environment variable or default value
|
|
func getEnvOrDefault(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|