feat: toggling Create/Join room button
This commit is contained in:
@@ -40,7 +40,7 @@ func (r *Room) UnmarshalBinary(data []byte) error {
|
||||
var ctx = context.Background()
|
||||
|
||||
type RoomManager interface {
|
||||
Get(roomName string) (Room, error) // but we need Get by name
|
||||
Get(roomName string) (Room, bool, error)
|
||||
Save(room Room) error
|
||||
}
|
||||
const roomRedisPrefix = "room"
|
||||
@@ -53,15 +53,18 @@ type RedisRM struct {
|
||||
Rdb *redis.Client
|
||||
}
|
||||
|
||||
func (redisRM RedisRM) Get(roomName string) (Room, error) {
|
||||
func (redisRM RedisRM) Get(roomName string) (Room, bool, error) {
|
||||
var readRoom Room
|
||||
err := redisRM.Rdb.Get(ctx, roomNameToRedisId(roomName)).Scan(&readRoom)
|
||||
if err == redis.Nil {
|
||||
return Room{}, false, nil
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("error reading room with id %s : %s", roomName, err)
|
||||
return Room{}, err
|
||||
return Room{}, false, err
|
||||
}
|
||||
|
||||
return readRoom, nil
|
||||
return readRoom, true, nil
|
||||
}
|
||||
|
||||
func (redisRM RedisRM) Save(room Room) error {
|
||||
|
||||
Reference in New Issue
Block a user