diff --git a/socketserver/cmd/statsweb/servers.go b/socketserver/cmd/statsweb/servers.go index d4818c61..d17e590f 100644 --- a/socketserver/cmd/statsweb/servers.go +++ b/socketserver/cmd/statsweb/servers.go @@ -12,7 +12,6 @@ import ( "bitbucket.org/stendec/frankerfacez/socketserver/server" "github.com/clarkduvall/hyperloglog" - "github.com/hashicorp/golang-lru" ) type serverFilter struct { diff --git a/socketserver/server/backend.go b/socketserver/server/backend.go index f41defde..3b7a8c3c 100644 --- a/socketserver/server/backend.go +++ b/socketserver/server/backend.go @@ -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" ) diff --git a/socketserver/server/publisher.go b/socketserver/server/publisher.go index 98ed2d19..e755c9e6 100644 --- a/socketserver/server/publisher.go +++ b/socketserver/server/publisher.go @@ -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, ","))) -} \ No newline at end of file +} diff --git a/socketserver/server/publisher_test.go b/socketserver/server/publisher_test.go index ad667d1b..c21696e5 100644 --- a/socketserver/server/publisher_test.go +++ b/socketserver/server/publisher_test.go @@ -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() diff --git a/socketserver/server/ratelimit.go b/socketserver/server/ratelimit.go index ad7b4e33..265277d6 100644 --- a/socketserver/server/ratelimit.go +++ b/socketserver/server/ratelimit.go @@ -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 } diff --git a/socketserver/server/ratelimit_test.go b/socketserver/server/ratelimit_test.go index f8ba87f9..393ef5e1 100644 --- a/socketserver/server/ratelimit_test.go +++ b/socketserver/server/ratelimit_test.go @@ -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() -} \ No newline at end of file +} diff --git a/socketserver/server/types.go b/socketserver/server/types.go index 3fa99084..b9eee5b5 100644 --- a/socketserver/server/types.go +++ b/socketserver/server/types.go @@ -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.