ЛР 3 - БВТ2303 - Голиков - на 5, трек 1 #4

Closed
Maximillan_Mercer wants to merge 36 commits from Maximillan_Mercer/mtusi2026lab3-fork:solution/BVT2303-Golikov into main
Showing only changes of commit 23b5cd0c3f - Show all commits
+22 -12
View File
@@ -9,12 +9,13 @@ import (
) )
type Config struct { type Config struct {
Host string Host string
Port string Port string
DatabaseURL string DatabaseURL string
SessionStore string SessionStore string
CacheURL string CacheURL string
SessionTTL time.Duration SessionTTL time.Duration
IdempotencyTTL time.Duration
} }
func Load() (*Config, error) { func Load() (*Config, error) {
@@ -36,6 +37,14 @@ func Load() (*Config, error) {
return nil, fmt.Errorf("SESSION_TTL_SECONDS должен быть положительным") 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")) store := strings.ToLower(getenv("SESSION_STORE", "postgres"))
switch store { switch store {
case "postgres", "redis", "valkey": case "postgres", "redis", "valkey":
@@ -44,12 +53,13 @@ func Load() (*Config, error) {
} }
return &Config{ return &Config{
Host: getenv("APP_HOST", "0.0.0.0"), Host: getenv("APP_HOST", "0.0.0.0"),
Port: getenv("APP_PORT", "8080"), Port: getenv("APP_PORT", "8080"),
DatabaseURL: dsn, DatabaseURL: dsn,
SessionStore: store, SessionStore: store,
CacheURL: cacheURL, CacheURL: cacheURL,
SessionTTL: time.Duration(ttlSeconds) * time.Second, SessionTTL: time.Duration(ttlSeconds) * time.Second,
IdempotencyTTL: time.Duration(idemSeconds) * time.Second,
}, nil }, nil
} }