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

View File

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