From 25185fb05a6cbb3d87748481f6a06865deb49977 Mon Sep 17 00:00:00 2001 From: Preet Date: Wed, 19 Mar 2025 14:35:50 +0000 Subject: [PATCH] Use struct{} instead of bool as value type map[T]struct{} is idiomatic way to use sets in go --- 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 bb5c0e3b..5417a132 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)