mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
feat(config): time interval parser
Simplifies handling of time intervals in config values.
This commit is contained in:
parent
83254a1f26
commit
03021af53c
1 changed files with 14 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue