Simplify loginStatus using max() builtin
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user