From 23b5cd0c3fb72a86fefb0df535a3446431894385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Tue, 6 Oct 2026 22:37:26 +0300 Subject: [PATCH] feat(config): lab3 read IDEMPOTENCY_TTL_SECONDS from env --- backend/internal/config/config.go | 34 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/backend/internal/config/config.go b/backend/internal/config/config.go index ef6fda7..b930405 100644 --- a/backend/internal/config/config.go +++ b/backend/internal/config/config.go @@ -9,12 +9,13 @@ import ( ) type Config struct { - Host string - Port string - DatabaseURL string - SessionStore string - CacheURL string - SessionTTL time.Duration + Host string + Port string + DatabaseURL string + SessionStore string + CacheURL string + SessionTTL time.Duration + IdempotencyTTL time.Duration } func Load() (*Config, error) { @@ -36,6 +37,14 @@ func Load() (*Config, error) { return nil, fmt.Errorf("SESSION_TTL_SECONDS должен быть положительным") } + idemSeconds, err := readInt("IDEMPOTENCY_TTL_SECONDS", 86400) + if err != nil { + return nil, fmt.Errorf("IDEMPOTENCY_TTL_SECONDS: %w", err) + } + if idemSeconds <= 0 { + return nil, fmt.Errorf("IDEMPOTENCY_TTL_SECONDS должен быть положительным") + } + store := strings.ToLower(getenv("SESSION_STORE", "postgres")) switch store { case "postgres", "redis", "valkey": @@ -44,12 +53,13 @@ func Load() (*Config, error) { } return &Config{ - Host: getenv("APP_HOST", "0.0.0.0"), - Port: getenv("APP_PORT", "8080"), - DatabaseURL: dsn, - SessionStore: store, - CacheURL: cacheURL, - SessionTTL: time.Duration(ttlSeconds) * time.Second, + Host: getenv("APP_HOST", "0.0.0.0"), + Port: getenv("APP_PORT", "8080"), + DatabaseURL: dsn, + SessionStore: store, + CacheURL: cacheURL, + SessionTTL: time.Duration(ttlSeconds) * time.Second, + IdempotencyTTL: time.Duration(idemSeconds) * time.Second, }, nil }