parseExpiresFromConfig parses expires value from config map. Supports both integer (hours or days) and string formats like "2h", "7d", "2w", "1m", "1y" Also supports boolean false to explicitly disable expiration (returns -1) Returns the number of hours, -1 if explicitly disabled (false), or 0 if in
(configMap map[string]any)
| 380 | // Note: For uint64 values, returns 0 if the value would overflow int. |
| 381 | // Note: Integer values without units are treated as days and converted to hours (for backward compatibility) |
| 382 | func parseExpiresFromConfig(configMap map[string]any) int { |
| 383 | timeDeltaLog.Printf("DEBUG: parseExpiresFromConfig called with configMap: %+v", configMap) |
| 384 | if expires, exists := configMap["expires"]; exists { |
| 385 | // Try numeric types first |
| 386 | switch v := expires.(type) { |
| 387 | case bool: |
| 388 | // false explicitly disables expiration |
| 389 | if !v { |
| 390 | timeDeltaLog.Print("expires set to false, expiration disabled") |
| 391 | return -1 |
| 392 | } |
| 393 | // true is not a valid expires value |
| 394 | return 0 |
| 395 | case int: |
| 396 | // Integer values without units are treated as days for backward compatibility |
| 397 | return v * 24 |
| 398 | case int64: |
| 399 | return int(v) * 24 |
| 400 | case float64: |
| 401 | return int(v) * 24 |
| 402 | case uint64: |
| 403 | // Check for overflow before converting uint64 to int |
| 404 | const maxInt = int(^uint(0) >> 1) |
| 405 | if v > uint64(maxInt/24) { |
| 406 | timeDeltaLog.Printf("uint64 value %d for expires exceeds max int value, returning 0", v) |
| 407 | return 0 |
| 408 | } |
| 409 | return int(v) * 24 |
| 410 | case string: |
| 411 | // Parse relative time specification like "2h", "7d", "2w", "1m", "1y" |
| 412 | return parseRelativeTimeSpec(v) |
| 413 | } |
| 414 | } |
| 415 | return 0 |
| 416 | } |
| 417 | |
| 418 | // parseRelativeTimeSpec parses a relative time specification string. |
| 419 | // Supports: h (hours), d (days), w (weeks), m (months ~30 days), y (years ~365 days) |