account/internal/config/config.go
GnomeZworc 5a5312097d
add cors handle
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-06-14 22:29:22 +02:00

50 lines
1.3 KiB
Go

package config
import (
"os"
"strconv"
"time"
)
type Config struct {
DatabaseURL string
Port string
Env string
OpenFIGIKey string
CoinGeckoKey string
PriceFetchInterval time.Duration
PriceCleanInterval time.Duration
SnapshotHorizonDays int
CORSAllowedOrigins string // "*" ou liste comma-séparée d'origines
}
func Load() *Config {
fetchInterval, err := time.ParseDuration(getenv("PRICE_FETCH_INTERVAL", "1h"))
if err != nil {
fetchInterval = time.Hour
}
horizonDays, err := strconv.Atoi(getenv("SNAPSHOT_HORIZON_DAYS", "30"))
if err != nil || horizonDays < 0 {
horizonDays = 30
}
return &Config{
DatabaseURL: getenv("DATABASE_URL", "postgres://account:account@localhost:5432/account?sslmode=disable"),
Port: getenv("PORT", "8080"),
Env: getenv("ENV", "development"),
OpenFIGIKey: os.Getenv("OPENFIGI_API_KEY"),
CoinGeckoKey: os.Getenv("COINGECKO_API_KEY"),
PriceFetchInterval: fetchInterval,
PriceCleanInterval: 24 * time.Hour,
SnapshotHorizonDays: horizonDays,
CORSAllowedOrigins: getenv("CORS_ALLOWED_ORIGINS", "*"),
}
}
func getenv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}