76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
DatabaseURL string
|
|
RedisURL string
|
|
JWTSecret string
|
|
CORSOrigins []string
|
|
AzureSpeechKey string
|
|
AzureRegion string
|
|
AzureMock bool
|
|
FlowiseBaseURL string
|
|
FlowiseChatflow string
|
|
FlowiseAPIKey string
|
|
DebugEnabled bool
|
|
DebugVerbose bool
|
|
LogLevel slog.Level
|
|
}
|
|
|
|
func Load() Config {
|
|
return Config{
|
|
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"),
|
|
FlowiseBaseURL: env("FLOWISE_BASE_URL", "http://localhost:3000"),
|
|
FlowiseChatflow: os.Getenv("FLOWISE_CHATFLOW_ID"),
|
|
FlowiseAPIKey: os.Getenv("FLOWISE_API_KEY"),
|
|
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
|
|
}
|
|
}
|