Simplify loginStatus using max() builtin

This commit is contained in:
Jan Meinl
2026-08-19 16:13:28 +02:00
parent 65bb2b351f
commit 24a4eee4a6
+2 -8
View File
@@ -119,18 +119,12 @@ func loginStatus(ip string) (int, int) {
} }
} }
a.times = kept a.times = kept
remaining := loginMaxAttempts - len(a.times) remaining := max(loginMaxAttempts - len(a.times), 0)
if remaining < 0 {
remaining = 0
}
retryAfter := 0 retryAfter := 0
if remaining == 0 && len(a.times) > 0 { if remaining == 0 && len(a.times) > 0 {
// Time until the oldest attempt falls out of the window. // Time until the oldest attempt falls out of the window.
next := a.times[0].Add(loginWindow).Sub(time.Now()) next := a.times[0].Add(loginWindow).Sub(time.Now())
retryAfter = int(next.Seconds()) + 1 retryAfter = max(int(next.Seconds()) + 1, 1)
if retryAfter < 1 {
retryAfter = 1
}
} }
return remaining, retryAfter return remaining, retryAfter
} }