mirror of https://github.com/gorilla/websocket.git
Use empty struct instead of bool in map value
This commit is contained in:
parent
cdedf21e58
commit
dad49c62a4
|
@ -8,7 +8,7 @@ package main
|
||||||
// clients.
|
// clients.
|
||||||
type Hub struct {
|
type Hub struct {
|
||||||
// Registered clients.
|
// Registered clients.
|
||||||
clients map[*Client]bool
|
clients map[*Client]struct{}
|
||||||
|
|
||||||
// Inbound messages from the clients.
|
// Inbound messages from the clients.
|
||||||
broadcast chan []byte
|
broadcast chan []byte
|
||||||
|
@ -25,7 +25,7 @@ func newHub() *Hub {
|
||||||
broadcast: make(chan []byte),
|
broadcast: make(chan []byte),
|
||||||
register: make(chan *Client),
|
register: make(chan *Client),
|
||||||
unregister: 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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case client := <-h.register:
|
case client := <-h.register:
|
||||||
h.clients[client] = true
|
h.clients[client] = struct{}{}
|
||||||
case client := <-h.unregister:
|
case client := <-h.unregister:
|
||||||
if _, ok := h.clients[client]; ok {
|
if _, ok := h.clients[client]; ok {
|
||||||
delete(h.clients, client)
|
delete(h.clients, client)
|
||||||
|
|
Loading…
Reference in New Issue