Changed naming of Client to ClientHandler

This commit is contained in:
Nicholas Thompson
2019-03-09 22:49:40 +02:00
committed by ncthompson
parent d30e0ecedd
commit eb74b967c7
2 changed files with 10 additions and 10 deletions

View File

@@ -24,8 +24,8 @@ var upgrader = websocket.Upgrader{
WriteBufferSize: 1024,
}
// Client is a middleman between the websocket connection and the hub.
type Client struct {
// ClientHandler is a middleman between the websocket connection and the hub.
type ClientHandler struct {
hub *Hub
// The websocket connection.
@@ -40,7 +40,7 @@ type Client struct {
// A goroutine running writePump is started for each connection. The
// application ensures that there is at most one writer to a connection by
// executing all writes from this goroutine.
func (c *Client) writePump() {
func (c *ClientHandler) writePump() {
ticker := time.NewTicker(pingPeriod)
defer func() {
ticker.Stop()
@@ -81,7 +81,7 @@ func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println(err)
return
}
client := &Client{hub: h, conn: conn, send: make(chan []byte, 256)}
client := &ClientHandler{hub: h, conn: conn, send: make(chan []byte, 256)}
client.hub.register <- client
// Allow collection of memory referenced by the caller by doing all work in

View File

@@ -8,24 +8,24 @@ import (
// clients.
type Hub struct {
// Registered clients.
clients map[*Client]bool
clients map[*ClientHandler]bool
// Inbound messages from the clients.
broadcast chan []byte
// Register requests from the clients.
register chan *Client
register chan *ClientHandler
// Unregister requests from clients.
unregister chan *Client
unregister chan *ClientHandler
}
func NewHub() *Hub {
tmp := &Hub{
broadcast: make(chan []byte),
register: make(chan *Client),
unregister: make(chan *Client),
clients: make(map[*Client]bool),
register: make(chan *ClientHandler),
unregister: make(chan *ClientHandler),
clients: make(map[*ClientHandler]bool),
}
go tmp.run()
return tmp