Improve IsUnexpectedCloseError examples

This commit is contained in:
Gary Burd 2016-01-19 18:24:46 -08:00
parent 615f23bc98
commit 5434f8b69b
2 changed files with 4 additions and 1 deletions

View File

@ -25,7 +25,7 @@ func ExampleIsUnexpectedCloseError(err error, c *websocket.Conn, req *http.Reque
messageType, p, err := c.ReadMessage()
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
log.Println("error: %v, user-agent: %v", err, req.Header.Get("User-Agent"))
log.Printf("error: %v, user-agent: %v", err, req.Header.Get("User-Agent"))
}
return
}

View File

@ -51,6 +51,9 @@ func (c *connection) readPump() {
for {
_, message, err := c.ws.ReadMessage()
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
log.Printf("error: %v", err)
}
break
}
h.broadcast <- message