1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-07 06:40:54 +00:00

Reformat, fix doc

This commit is contained in:
Kane York 2017-02-02 23:08:21 -08:00
parent 50e295c834
commit 7be7fc5c3a
7 changed files with 23 additions and 24 deletions

View file

@ -12,7 +12,6 @@ import (
"bitbucket.org/stendec/frankerfacez/socketserver/server" "bitbucket.org/stendec/frankerfacez/socketserver/server"
"github.com/clarkduvall/hyperloglog" "github.com/clarkduvall/hyperloglog"
"github.com/hashicorp/golang-lru"
) )
type serverFilter struct { type serverFilter struct {

View file

@ -12,11 +12,10 @@ import (
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"sync" cache "github.com/patrickmn/go-cache"
"github.com/pmylund/go-cache"
"golang.org/x/crypto/nacl/box" "golang.org/x/crypto/nacl/box"
) )

View file

@ -7,6 +7,7 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -25,7 +26,7 @@ var CachedLSMLock sync.RWMutex
func cachedMessageJanitor() { func cachedMessageJanitor() {
for { for {
time.Sleep(1*time.Hour) time.Sleep(1 * time.Hour)
cachedMessageJanitor_do() cachedMessageJanitor_do()
} }
} }
@ -212,7 +213,7 @@ func HTTPBackendCachedPublish(w http.ResponseWriter, r *http.Request) {
close(ch) close(ch)
}() }()
select { select {
case time.After(3*time.Second): case time.After(3 * time.Second):
count = -1 count = -1
case <-ch: case <-ch:
} }
@ -277,7 +278,7 @@ func HTTPBackendUncachedPublish(w http.ResponseWriter, r *http.Request) {
close(ch) close(ch)
}() }()
select { select {
case time.After(3*time.Second): case time.After(3 * time.Second):
count = -1 count = -1
case <-ch: case <-ch:
} }

View file

@ -16,9 +16,9 @@ func TestExpiredCleanup(t *testing.T) {
defer DumpBacklogData() defer DumpBacklogData()
var zeroTime time.Time var zeroTime time.Time
hourAgo := time.Now().Add(-1*time.Hour) hourAgo := time.Now().Add(-1 * time.Hour)
now := time.Now() now := time.Now()
hourFromNow := time.Now().Add(1*time.Hour) hourFromNow := time.Now().Add(1 * time.Hour)
saveLastMessage(cmd, channel, hourAgo, "1", false) saveLastMessage(cmd, channel, hourAgo, "1", false)
saveLastMessage(cmd, channel2, now, "2", false) saveLastMessage(cmd, channel2, now, "2", false)
@ -26,11 +26,11 @@ func TestExpiredCleanup(t *testing.T) {
if len(CachedLastMessages) != 1 { if len(CachedLastMessages) != 1 {
t.Error("messages not saved") t.Error("messages not saved")
} }
if len(CachedLastMessages[cmd]) != 2{ if len(CachedLastMessages[cmd]) != 2 {
t.Error("messages not saved") t.Error("messages not saved")
} }
time.Sleep(2*time.Millisecond) time.Sleep(2 * time.Millisecond)
cachedMessageJanitor_do() cachedMessageJanitor_do()
@ -47,7 +47,7 @@ func TestExpiredCleanup(t *testing.T) {
t.Error("messages not saved") t.Error("messages not saved")
} }
time.Sleep(2*time.Millisecond) time.Sleep(2 * time.Millisecond)
cachedMessageJanitor_do() cachedMessageJanitor_do()

View file

@ -1,8 +1,8 @@
package server package server
import ( import (
"time"
"io" "io"
"time"
) )
// A RateLimit supports a constant number of Performed() calls every // A RateLimit supports a constant number of Performed() calls every
@ -22,7 +22,7 @@ type RateLimit interface {
io.Closer io.Closer
} }
type timeRateLimit struct{ type timeRateLimit struct {
count int count int
period time.Duration period time.Duration
ch chan struct{} ch chan struct{}
@ -30,7 +30,7 @@ type timeRateLimit struct{
} }
// Construct a new RateLimit with the given count and duration. // Construct a new RateLimit with the given count and duration.
func NewRateLimit(count int, period time.Duration) (RateLimit) { func NewRateLimit(count int, period time.Duration) RateLimit {
return &timeRateLimit{ return &timeRateLimit{
count: count, count: count,
period: period, period: period,
@ -64,13 +64,14 @@ func (r *timeRateLimit) Close() error {
} }
type unlimited struct{} type unlimited struct{}
var unlimitedInstance unlimited var unlimitedInstance unlimited
// Unlimited returns a RateLimit that never blocks. The Run() and Close() calls are no-ops. // Unlimited returns a RateLimit that never blocks. The Run() and Close() calls are no-ops.
func Unlimited() (RateLimit) { func Unlimited() RateLimit {
return unlimitedInstance return unlimitedInstance
} }
func (r unlimited) Run() { } func (r unlimited) Run() {}
func (r unlimited) Performed() { } func (r unlimited) Performed() {}
func (r unlimited) Close() error { return nil } func (r unlimited) Close() error { return nil }

View file

@ -1,8 +1,8 @@
package server package server
import ( import (
"time"
"testing" "testing"
"time"
) )
var exampleData = []string{} var exampleData = []string{}

View file

@ -108,8 +108,7 @@ type ClientInfo struct {
// True if the client has already sent the 'ready' command // True if the client has already sent the 'ready' command
ReadyComplete bool ReadyComplete bool
// Server-initiated messages should be sent here // Server-initiated messages should be sent via the Send() method
// This field will be nil before it is closed.
MessageChannel chan<- ClientMessage MessageChannel chan<- ClientMessage
// Closed when the client is shutting down. // Closed when the client is shutting down.