From 03021af53c46b641948ac26859e49c7816b2d3b7 Mon Sep 17 00:00:00 2001 From: gudvinr Date: Mon, 18 Aug 2025 23:10:18 +0300 Subject: [PATCH] feat(config): time interval parser Simplifies handling of time intervals in config values. --- internal/config/parser.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/config/parser.go b/internal/config/parser.go index a5b6a125..836c7d65 100644 --- a/internal/config/parser.go +++ b/internal/config/parser.go @@ -358,6 +358,20 @@ func parseBytes(value string, fallback []byte) []byte { return []byte(value) } +// parseInterval converts an integer "value" to [time.Duration] using "unit" as multiplier. +func parseInterval(value string, unit time.Duration, fallback time.Duration) time.Duration { + if value == "" { + return fallback + } + + v, err := strconv.Atoi(value) + if err != nil { + return fallback + } + + return time.Duration(v) * unit +} + func readSecretFile(filename, fallback string) string { data, err := os.ReadFile(filename) if err != nil {