Skip to content
This repository was archived by the owner on Sep 29, 2024. It is now read-only.

Commit bc0cd32

Browse files
committed
refactor: move genNewV4UUId to helpers file
1 parent 6f30449 commit bc0cd32

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

helpers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package socketio
2+
3+
import "github.com/gofrs/uuid"
4+
5+
func newV4UUID() string {
6+
return uuid.Must(uuid.NewV4()).String()
7+
}

redis_broadcast.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strings"
77
"sync"
88

9-
uuid "github.com/gofrs/uuid"
109
"github.com/gomodule/redigo/redis"
1110
)
1211

@@ -123,7 +122,7 @@ func newRedisBroadcast(nsp string, adapter *RedisAdapterOptions) (*redisBroadcas
123122
bc.sub = redis.PubSubConn{Conn: sub}
124123

125124
bc.nsp = nsp
126-
bc.uid = uuid.Must(uuid.NewV4()).String()
125+
bc.uid = newV4UUID()
127126
bc.key = bc.prefix + "#" + bc.nsp + "#" + bc.uid
128127
bc.reqChannel = bc.prefix + "-request#" + bc.nsp
129128
bc.resChannel = bc.prefix + "-response#" + bc.nsp
@@ -355,7 +354,7 @@ func (bc *redisBroadcast) Clear(room string) {
355354
func (bc *redisBroadcast) publishClear(room string) {
356355
req := clearRoomRequest{
357356
RequestType: clearRoomReqType,
358-
RequestID: uuid.Must(uuid.NewV4()).String(),
357+
RequestID: newV4UUID(),
359358
Room: room,
360359
UUID: bc.uid,
361360
}
@@ -456,7 +455,7 @@ func (bc *redisBroadcast) Len(room string) int {
456455

457456
req := roomLenRequest{
458457
RequestType: roomLenReqType,
459-
RequestID: uuid.Must(uuid.NewV4()).String(),
458+
RequestID: newV4UUID(),
460459
Room: room,
461460
}
462461

@@ -494,7 +493,7 @@ func (bc *redisBroadcast) AllRooms() []string {
494493

495494
req := allRoomRequest{
496495
RequestType: allRoomReqType,
497-
RequestID: uuid.Must(uuid.NewV4()).String(),
496+
RequestID: newV4UUID(),
498497
}
499498
reqJSON, _ := json.Marshal(&req)
500499

0 commit comments

Comments
 (0)