debug actions
This commit is contained in:
parent
2dc44348a4
commit
45b4ec7302
@ -2,6 +2,7 @@ package limiter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,9 +31,11 @@ func (l *Limiter) CheckAllowed(userid string) error {
|
|||||||
for i := 0; i < len(l.Logs[userid]); i++ {
|
for i := 0; i < len(l.Logs[userid]); i++ {
|
||||||
/* If the timestamp plus the timelimit is happened before "Now" */
|
/* If the timestamp plus the timelimit is happened before "Now" */
|
||||||
if l.Logs[userid][i].Timestamp.Add(l.TimeLimit).Before(time.Now()) {
|
if l.Logs[userid][i].Timestamp.Add(l.TimeLimit).Before(time.Now()) {
|
||||||
|
log.Printf("Expired entry\n")
|
||||||
expiredEntries = append(expiredEntries, i)
|
expiredEntries = append(expiredEntries, i)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
log.Printf("Increasing counter\n")
|
||||||
counter++
|
counter++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -42,6 +45,7 @@ func (l *Limiter) CheckAllowed(userid string) error {
|
|||||||
l.removeAction(userid, expiredEntries[i])
|
l.removeAction(userid, expiredEntries[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Checking if %d is >= %d", counter, l.RateLimit)
|
||||||
if counter >= l.RateLimit {
|
if counter >= l.RateLimit {
|
||||||
return errors.New("rate limit exceeded")
|
return errors.New("rate limit exceeded")
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user