Browse Source

feat: removed duplicate log and log broadcasts

Fela Maslen 5 năm trước cách đây
mục cha
commit
dbf1de68cc

+ 3 - 1
music-player/pkg/server/actions.go

@@ -3,6 +3,7 @@ package server
 import (
 	"encoding/json"
 
+	"github.com/felamaslen/go-music-player/pkg/logger"
 	"github.com/go-redis/redis/v7"
 )
 
@@ -19,10 +20,11 @@ type Action struct {
 	Payload    interface{} `json:"payload"`
 }
 
-func broadcastAction(thisPodClients *map[string]*Client, action *Action) []error {
+func broadcastAction(l *logger.Logger, thisPodClients *map[string]*Client, action *Action) []error {
 	var errors []error
 
 	for _, client := range *thisPodClients {
+		l.Debug("[->Client] %s (%s)\n", action.Type, client.name)
 		if err := client.send(action); err != nil {
 			errors = append(errors, err)
 		}

+ 0 - 2
music-player/pkg/server/clients.go

@@ -97,8 +97,6 @@ func (c *Client) subscribeToMe(l *logger.Logger, rdb *redis.Client) {
 			})
 			c.exposeToNetwork(l, rdb)
 		} else {
-			l.Debug("[->Client] %s (%s)\n", actionFromClient.Type, c.name)
-
 			actionFromClient.FromClient = &c.name
 
 			if err := publishAction(rdb, &actionFromClient); err != nil {

+ 1 - 1
music-player/pkg/server/pubsub.go

@@ -94,7 +94,7 @@ func subscribeToBroadcast(
 					l.Debug("[<-Client] %s (%s)\n", actionFromPubsub.Type, *actionFromPubsub.FromClient)
 				}
 
-				errors := broadcastAction(thisPodClients, &actionFromPubsub)
+				errors := broadcastAction(l, thisPodClients, &actionFromPubsub)
 
 				if len(errors) > 0 {
 					l.Warn("Error broadcasting: %v\n", errors)