package config import ( "os" "strconv" "strings" ) type SmtpSettings struct { Email string Password string Host string Port int } type Settings struct { Environment string CorsAllowedOrigins []string PublicURL string UploadDir string JWTSecret string DBFile string Port string Smtp SmtpSettings } func (s Settings) IsProduction() bool { return s.Environment == "production" } func NewSettingsFromEnv() (Settings, error) { smtpPort, err := strconv.Atoi(os.Getenv("SMTP_PORT")) if err != nil { return Settings{}, err } return Settings{ Environment: os.Getenv("ENVIRONMENT"), CorsAllowedOrigins: parseCorsAllowedOrigins(os.Getenv("CORS_ALLOWED_ORIGINS")), PublicURL: os.Getenv("PUBLIC_URL"), UploadDir: os.Getenv("UPLOAD_DIR"), JWTSecret: os.Getenv("JWT_SECRET"), DBFile: os.Getenv("DB_FILE"), Port: os.Getenv("PORT"), Smtp: SmtpSettings{ Email: os.Getenv("SMTP_EMAIL"), Password: os.Getenv("SMTP_PASSWORD"), Host: os.Getenv("SMTP_HOST"), Port: smtpPort, }, }, nil } func parseCorsAllowedOrigins(raw string) []string { if raw == "" { return nil } return strings.Split(raw, ";") }