handle close
This commit is contained in:
parent
6bd36a59c5
commit
5570e53d99
1 changed files with 17 additions and 2 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,14 +107,18 @@ func (ws *wsSession) Go() error {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_, rdr, err := ws.NextReader()
|
_, rdr, err := ws.NextReader()
|
||||||
if err != nil {
|
switch {
|
||||||
|
case websocket.IsCloseError(err, websocket.CloseGoingAway):
|
||||||
|
return nil
|
||||||
|
case err == nil:
|
||||||
|
case err != nil:
|
||||||
log.Error().Err(err).Str("remote", ws.ec.Request().RemoteAddr).Msg("websocket read fail")
|
log.Error().Err(err).Str("remote", ws.ec.Request().RemoteAddr).Msg("websocket read fail")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ws.h.handleMsg(rdr)
|
err = ws.h.handleMsg(rdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Error().Err(err).Msg("handleMsg")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,5 +195,15 @@ func (ws *cmdHandler) handleMsg(r io.Reader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
nd := newData(cmd)
|
nd := newData(cmd)
|
||||||
|
err = mapstructure.Decode(&msgMap, &nd)
|
||||||
|
if err != nil {
|
||||||
|
ws.writeError(id, Error{
|
||||||
|
Code: "invalid_format",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return hand(ws, id, cmd, nd)
|
return hand(ws, id, cmd, nd)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue