package config import ( "log/slog" "os" "strings" ) type Config struct { PronunciationStrategy string CourseTaskMode string DeepSeekAPIKey string MistralAPIKey string Port string DatabaseURL string RedisURL string JWTSecret string CORSOrigins []string AzureSpeechKey string AzureRegion string AzureMock bool FlowiseBaseURL string FlowiseChatflow string FlowiseAPIKey string FlowiseCourseChatflow string FlowiseCourseAPIKey string FlowiseCourseTeacher string FlowiseCourseTeacherAPIKey string DebugEnabled bool DebugVerbose bool LogLevel slog.Level } func Load() Config { return Config{ PronunciationStrategy: env("PRONUNCIATION_STRATEGY", "statistical"), CourseTaskMode: env("COURSE_TASK_MODE", "bank"), DeepSeekAPIKey: os.Getenv("DEEPSEEK_API_KEY"), MistralAPIKey: os.Getenv("MISTRAL_API_KEY"), Port: env("API_PORT", "8080"), DatabaseURL: env("DATABASE_URL", "postgres://speech:speech_dev_password@localhost:5432/speech?sslmode=disable"), RedisURL: env("REDIS_URL", "redis://localhost:6379"), JWTSecret: env("APP_JWT_SECRET", "dev-secret-change-me"), CORSOrigins: splitCSV(env("CORS_ORIGINS", "http://localhost:5173,http://localhost:8080")), AzureSpeechKey: os.Getenv("AZURE_SPEECH_KEY"), AzureRegion: os.Getenv("AZURE_SPEECH_REGION"), AzureMock: strings.EqualFold(env("AZURE_ENABLE_MOCK", "true"), "true"), DebugEnabled: strings.EqualFold(env("DEBUG_ENABLED", "false"), "true"), DebugVerbose: strings.EqualFold(env("DEBUG_VERBOSE", "false"), "true"), LogLevel: parseLogLevel(env("LOG_LEVEL", "info")), } } func env(key, fallback string) string { if value := strings.TrimSpace(os.Getenv(key)); value != "" { return value } return fallback } func splitCSV(value string) []string { parts := strings.Split(value, ",") out := make([]string, 0, len(parts)) for _, part := range parts { part = strings.TrimSpace(part) if part != "" { out = append(out, part) } } return out } func parseLogLevel(value string) slog.Level { switch strings.ToLower(strings.TrimSpace(value)) { case "debug": return slog.LevelDebug case "warn", "warning": return slog.LevelWarn case "error": return slog.LevelError default: return slog.LevelInfo } }