mirror of
https://github.com/wisplite/tether.git
synced 2026-05-01 06:22:41 -05:00
add new client handler to isolate websockets from engine
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package reactivity
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
ID string
|
||||
Conn *websocket.Conn
|
||||
Send chan []byte
|
||||
}
|
||||
|
||||
func NewClient(conn *websocket.Conn) *Client {
|
||||
return &Client{ID: uuid.NewString(), Conn: conn, Send: make(chan []byte, 256)}
|
||||
}
|
||||
|
||||
func (c *Client) WritePump() {
|
||||
defer c.Conn.Close()
|
||||
|
||||
for message := range c.Send {
|
||||
err := c.Conn.WriteMessage(websocket.TextMessage, message)
|
||||
if err != nil {
|
||||
slog.Error("Client write pump failed", "error", err, "client", c.ID)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user