55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
type Config struct {
|
|
Port int
|
|
AWConnStr string
|
|
WWIConnStr string
|
|
PostgresDSN string
|
|
OtelCollectorEndpoint string
|
|
OtelServiceName string
|
|
OtelServiceNamespace string
|
|
DefaultTopN int
|
|
ForecastHorizonDays int
|
|
DefaultHistoryDays int
|
|
}
|
|
|
|
func Load() Config {
|
|
port, _ := strconv.Atoi(getEnv("PORT", "8080"))
|
|
topN, _ := strconv.Atoi(getEnv("DEFAULT_TOP_N", "10"))
|
|
forecastDays, _ := strconv.Atoi(getEnv("FORECAST_HORIZON_DAYS", "30"))
|
|
historyDays, _ := strconv.Atoi(getEnv("DEFAULT_HISTORY_DAYS", "365"))
|
|
return Config{
|
|
Port: port,
|
|
AWConnStr: mustEnv("AW_MSSQL_DSN"),
|
|
WWIConnStr: mustEnv("WWI_MSSQL_DSN"),
|
|
PostgresDSN: mustEnv("POSTGRES_DSN"),
|
|
OtelCollectorEndpoint: getEnv("OTEL_COLLECTOR_ENDPOINT", "http://localhost:4318"),
|
|
OtelServiceName: getEnv("OTEL_SERVICE_NAME", "otel-bi-analytics"),
|
|
OtelServiceNamespace: getEnv("OTEL_SERVICE_NAMESPACE", "final-thesis"),
|
|
DefaultTopN: topN,
|
|
ForecastHorizonDays: forecastDays,
|
|
DefaultHistoryDays: historyDays,
|
|
}
|
|
}
|
|
|
|
func getEnv(key, fallback string) string {
|
|
if v, ok := os.LookupEnv(key); ok && v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func mustEnv(key string) string {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
panic(fmt.Sprintf("required environment variable %s is not set", key))
|
|
}
|
|
return v
|
|
}
|