mirror of
https://github.com/m1k1o/neko.git
synced 2025-06-10 23:03:05 +02:00
log ws send/recieve
This commit is contained in:
parent
d5bff32302
commit
7576d8c1da
2 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
package websocket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
@ -9,6 +10,7 @@ import (
|
|||
|
||||
type WebSocket struct {
|
||||
id string
|
||||
ws WebSocketHandler
|
||||
connection *websocket.Conn
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
@ -29,7 +31,18 @@ func (socket *WebSocket) Send(v interface{}) error {
|
|||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue