package ws import ( "sync" ) type Room struct { Id string clients map[string]*Client rwmux *sync.RWMutex } func NewRoom(id string) *Room { room := new(Room) room.Id = id room.clients = make(map[string]*Client, 0) room.rwmux = new(sync.RWMutex) return room } func (t *Room) Len() int { t.rwmux.RLock() defer t.rwmux.RUnlock() return len(t.clients) } func (t *Room) DeleteClient(clientId string) { t.rwmux.Lock() defer t.rwmux.Unlock() delete(t.clients, clientId) }