Skip to content

Commit

Permalink
common: packet
Browse files Browse the repository at this point in the history
  • Loading branch information
krishpranav committed Jun 6, 2023
1 parent 00b04e8 commit 586fdbe
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/common/packet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package common

import (
"encoding/json"

"github.com/gorilla/websocket"
)

type Packet struct {
PType string `json:"type"`
Data string `json:"data"`
}

type PacketClient struct {
conn *websocket.Conn
}

func NewPacketClient(conn *websocket.Conn) *PacketClient {
return &PacketClient{
conn: conn,
}
}

func (c *PacketClient) Send(packet Packet) error {
data, err := json.Marshal(packet)
if err != nil {
return err
}

c.conn.WriteMessage(websocket.TextMessage, data)
return nil
}

0 comments on commit 586fdbe

Please sign in to comment.