From eb74b967c72c342038626d00f0ebf63f2c7742a8 Mon Sep 17 00:00:00 2001 From: Nicholas Thompson Date: Sat, 9 Mar 2019 22:49:40 +0200 Subject: [PATCH] Changed naming of Client to ClientHandler --- websocket/{client.go => clienthandler.go} | 8 ++++---- websocket/hub.go | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) rename websocket/{client.go => clienthandler.go} (89%) diff --git a/websocket/client.go b/websocket/clienthandler.go similarity index 89% rename from websocket/client.go rename to websocket/clienthandler.go index 03d4af4..2c32197 100644 --- a/websocket/client.go +++ b/websocket/clienthandler.go @@ -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 diff --git a/websocket/hub.go b/websocket/hub.go index f73a165..878db9d 100644 --- a/websocket/hub.go +++ b/websocket/hub.go @@ -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