feat(config): lab3 read IDEMPOTENCY_TTL_SECONDS from env
This commit is contained in:
@@ -15,6 +15,7 @@ type Config struct {
|
|||||||
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":
|
||||||
@@ -50,6 +59,7 @@ func Load() (*Config, error) {
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user