Use empty struct instead of bool in map value

This commit is contained in:
invzhi 2017-12-21 11:56:10 +08:00
parent cdedf21e58
commit dad49c62a4
1 changed files with 3 additions and 3 deletions

View File

@ -8,7 +8,7 @@ package main
// clients.
type Hub struct {
// Registered clients.
clients map[*Client]bool
clients map[*Client]struct{}
// Inbound messages from the clients.
broadcast chan []byte
@ -25,7 +25,7 @@ func newHub() *Hub {
broadcast: make(chan []byte),
register: make(chan *Client),
unregister: make(chan *Client),
clients: make(map[*Client]bool),
clients: make(map[*Client]struct{}),
}
}
@ -33,7 +33,7 @@ func (h *Hub) run() {
for {
select {
case client := <-h.register:
h.clients[client] = true
h.clients[client] = struct{}{}
case client := <-h.unregister:
if _, ok := h.clients[client]; ok {
delete(h.clients, client)