Staticcheck (#464)

Using `go get -u honnef.co/go/tools/cmd/staticcheck`
Uneaarthed a couple of real bugs
This commit is contained in:
Raja Subramanian
2022-02-25 12:04:08 +05:30
committed by GitHub
parent 5a4181b581
commit 0170cc1cb6
19 changed files with 32 additions and 41 deletions
+2 -2
View File
@@ -139,7 +139,7 @@ func (s *RedisStore) LockRoom(_ context.Context, name livekit.RoomName, duration
}
// stop waiting past lock duration
if time.Now().Sub(startTime) > duration {
if time.Since(startTime) > duration {
break
}
@@ -282,7 +282,7 @@ func (s *RedisStore) ListEgress(_ context.Context, roomID livekit.RoomID) ([]*li
return nil, err
}
data, err := s.rc.HMGet(s.ctx, EgressKey, ids...).Result()
data, _ := s.rc.HMGet(s.ctx, EgressKey, ids...).Result()
for _, d := range data {
if d == nil {
continue
+2 -2
View File
@@ -40,7 +40,7 @@ func TestCreateRoom(t *testing.T) {
node.Stats.NumTracksIn = 100
node.Stats.NumTracksOut = 100
ra, conf := newTestRoomAllocator(t, conf, node)
ra, _ := newTestRoomAllocator(t, conf, node)
_, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"})
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
@@ -56,7 +56,7 @@ func TestCreateRoom(t *testing.T) {
node.Stats.BytesInPerSec = 1000
node.Stats.BytesOutPerSec = 1000
ra, conf := newTestRoomAllocator(t, conf, node)
ra, _ := newTestRoomAllocator(t, conf, node)
_, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"})
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
+1 -1
View File
@@ -381,7 +381,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
return
}
if time.Now().Sub(lastTokenUpdate) > tokenRefreshInterval {
if time.Since(lastTokenUpdate) > tokenRefreshInterval {
pLogger.Debugw("refreshing client token after interval")
// refresh token with the first API Key/secret pair
if err := r.refreshToken(participant); err != nil {
+1 -1
View File
@@ -96,7 +96,7 @@ func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.Partic
// this is new connection for existing participant - with publish only permissions
if publishParam != "" {
// Make sure grant has CanPublish set,
if claims.Video.CanPublish != nil && *claims.Video.CanPublish == false {
if claims.Video.CanPublish != nil && !*claims.Video.CanPublish {
return "", routing.ParticipantInit{}, http.StatusUnauthorized, rtc.ErrPermissionDenied
}
// Make sure by default subscribe is off
+1 -1
View File
@@ -279,7 +279,7 @@ func (s *LivekitServer) healthCheck(w http.ResponseWriter, _ *http.Request) {
if s.Node().Stats != nil {
updatedAt = time.Unix(s.Node().Stats.UpdatedAt, 0)
}
if time.Now().Sub(updatedAt) > 4*time.Second {
if time.Since(updatedAt) > 4*time.Second {
w.WriteHeader(http.StatusNotAcceptable)
_, _ = w.Write([]byte(fmt.Sprintf("Not Ready\nNode Updated At %s", updatedAt)))
return