Some formatting fixes

This commit is contained in:
Leonid Bugaev
2014-10-26 13:25:18 +03:00
parent 58c7e12d1f
commit 7864808e5e
2 changed files with 5 additions and 6 deletions
+4 -4
View File
@@ -3,10 +3,10 @@ package main
import (
"fmt"
"io"
"math/rand"
"strconv"
"strings"
"time"
"math/rand"
)
type Limiter struct {
@@ -40,21 +40,21 @@ func NewLimiter(plugin interface{}, options string) io.ReadWriter {
}
func (l *Limiter) isLimited() bool {
if (l.isPercent) {
if l.isPercent {
return l.limit <= rand.Intn(100)
}
if (time.Now().UnixNano() - l.currentTime) > time.Second.Nanoseconds() {
l.currentTime = time.Now().UnixNano()
l.currentRPS = 0
}
}
if l.currentRPS >= l.limit {
return true
}
l.currentRPS++
return false
}
+1 -2
View File
@@ -54,7 +54,6 @@ func TestInputLimiter(t *testing.T) {
close(quit)
}
// Should limit all requests
func TestPercentLimiter1(t *testing.T) {
wg := new(sync.WaitGroup)
@@ -102,4 +101,4 @@ func TestPercentLimiter2(t *testing.T) {
wg.Wait()
close(quit)
}
}