log ws send/recieve
This commit is contained in:
parent
d5bff32302
commit
7576d8c1da
@ -1,6 +1,7 @@
|
|||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ import (
|
|||||||
|
|
||||||
type WebSocket struct {
|
type WebSocket struct {
|
||||||
id string
|
id string
|
||||||
|
ws WebSocketHandler
|
||||||
connection *websocket.Conn
|
connection *websocket.Conn
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
@ -29,7 +31,18 @@ func (socket *WebSocket) Send(v interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return socket.connection.WriteJSON(v)
|
raw, err := json.Marshal(v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.ws.logger.Debug().
|
||||||
|
Str("session", socket.id).
|
||||||
|
Str("address", socket.connection.RemoteAddr().String()).
|
||||||
|
Str("raw", string(raw)).
|
||||||
|
Msg("sending message to client")
|
||||||
|
|
||||||
|
return socket.connection.WriteMessage(websocket.TextMessage, raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (socket *WebSocket) Destroy() error {
|
func (socket *WebSocket) Destroy() error {
|
||||||
|
@ -240,6 +240,7 @@ func (ws *WebSocketHandler) handle(connection *websocket.Conn, id string) {
|
|||||||
case raw := <-bytes:
|
case raw := <-bytes:
|
||||||
ws.logger.Debug().
|
ws.logger.Debug().
|
||||||
Str("session", id).
|
Str("session", id).
|
||||||
|
Str("address", connection.RemoteAddr().String()).
|
||||||
Str("raw", string(raw)).
|
Str("raw", string(raw)).
|
||||||
Msg("recieved message from client")
|
Msg("recieved message from client")
|
||||||
if err := ws.handler.Message(id, raw); err != nil {
|
if err := ws.handler.Message(id, raw); err != nil {
|
||||||
|
Reference in New Issue
Block a user