1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-27 21:05:53 +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"
"github.com/clarkduvall/hyperloglog"
"github.com/hashicorp/golang-lru"
)
type serverFilter struct {

View file

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

View file

@ -7,13 +7,14 @@ import (
"strings"
"sync"
"time"
"github.com/pkg/errors"
)
// LastSavedMessage contains a reply to a command along with an expiration time.
type LastSavedMessage struct {
Expires time.Time
Data string
Data string
}
// map is command -> channel -> data
@ -25,7 +26,7 @@ var CachedLSMLock sync.RWMutex
func cachedMessageJanitor() {
for {
time.Sleep(1*time.Hour)
time.Sleep(1 * time.Hour)
cachedMessageJanitor_do()
}
}
@ -212,7 +213,7 @@ func HTTPBackendCachedPublish(w http.ResponseWriter, r *http.Request) {
close(ch)
}()
select {
case time.After(3*time.Second):
case time.After(3 * time.Second):
count = -1
case <-ch:
}
@ -277,7 +278,7 @@ func HTTPBackendUncachedPublish(w http.ResponseWriter, r *http.Request) {
close(ch)
}()
select {
case time.After(3*time.Second):
case time.After(3 * time.Second):
count = -1
case <-ch:
}
@ -300,4 +301,4 @@ func HTTPGetSubscriberCount(w http.ResponseWriter, r *http.Request) {
channel := formData.Get("channel")
fmt.Fprint(w, CountSubscriptions(strings.Split(channel, ",")))
}
}

View file

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

View file

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

View file

@ -1,8 +1,8 @@
package server
import (
"time"
"testing"
"time"
)
var exampleData = []string{}
@ -37,4 +37,4 @@ func TestRateLimit(t *testing.T) {
t.Error("ratelimiter improperly waited when tokens were available")
}
rl.Close()
}
}

View file

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