From dad49c62a46da12fc796b1d36efb4bbe97b5cbef Mon Sep 17 00:00:00 2001 From: invzhi Date: Thu, 21 Dec 2017 11:56:10 +0800 Subject: [PATCH] Use empty struct instead of bool in map value --- examples/chat/hub.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/chat/hub.go b/examples/chat/hub.go index 7f07ea0..bfcf41a 100644 --- a/examples/chat/hub.go +++ b/examples/chat/hub.go @@ -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)