寬哥云原生Go語言入門到腳手架項(xiàng)目實(shí)戰(zhàn)
// 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 {