宽哥云原生Go语言入门到脚手架项目实战
// Client is a middleman between the websocket connection and the hub.type Client struct {
hub *Hub // The websocket connection.
conn *websocket.Conn // Buffered channel of outbound messages.
send chan []byte}// readPump pumps messages from the websocket connection to the hub.//// The application runs readPump in a per-connection goroutine. The application// ensures that there is at most one reader on a connection by executing all// reads from this goroutine.func (c *Client) readPump() {
defer func() {
c.hub.unregister <- c
c.conn.Close()
}()
c.conn.SetReadLimit(maxMessageSize)
c.conn.SetReadDeadline(time.Now().Add(pongWait))
c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
for {
_, message, err := c.conn.ReadMessage()
if err != nil {