package chat import ( "sync" ) type ClientMap struct { Clients map[*Client]bool sync.Mutex } var ClientHandler = ClientMap{ Clients: map[*Client]bool{}, Mutex: sync.Mutex{}, } func (c *ClientMap) AddClient(client *Client) { c.Lock() c.Clients[client] = true c.Unlock() } func (c *ClientMap) DeleteClient(ID string) { c.Lock() for client := range c.Clients { if client.ID == ID { delete(c.Clients, client) } } c.Unlock() } func (c *ClientMap) FindClientsByStreamer(streamer string) []*Client { c.Lock() var clients []*Client for client := range c.Clients { // check if the client is following the given streamer for s, _ := range client.FollowingStreamers { if s == streamer { clients = append(clients, client) break } } } c.Unlock() return clients }