socket

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectedClient

type ConnectedClient struct {
	ID           int64
	Connection   *websocket.Conn
	SendMessage  chan []byte
	EntityFilter map[string]bool
	// contains filtered or unexported fields
}

ConnectedClient represents a single WebSocket client connection

type DataChangeEvent

type DataChangeEvent struct {
	Type      EventType `json:"type"`
	Entity    string    `json:"entity"`
	Data      any       `json:"data"`
	Timestamp time.Time `json:"timestamp"`
}

DataChangeEvent represents a change in our data that clients should know about

type EventType

type EventType string

EventType defines the type of data change event

const (
	EventCreated EventType = "created"
	EventUpdated EventType = "updated"
	EventDeleted EventType = "deleted"
)

type SocketManager

type SocketManager struct {
	// contains filtered or unexported fields
}

SocketManager manages all WebSocket connections and broadcasts events

func NewSocketManager

func NewSocketManager() *SocketManager

NewSocketManager creates and initializes a new WebSocket manager

func (*SocketManager) BroadcastEvent

func (manager *SocketManager) BroadcastEvent(eventType EventType, entity string, data any)

BroadcastEvent broadcasts a data change event to all connected clients This is the public method that repositories will call

func (*SocketManager) HandleWebSocket

func (manager *SocketManager) HandleWebSocket(response http.ResponseWriter, request *http.Request)

HandleWebSocket upgrades HTTP connections to WebSocket and manages the client lifecycle This is the HTTP handler function for WebSocket connections

func (*SocketManager) Run

func (manager *SocketManager) Run()

Run starts the WebSocket manager's main event loop This should be run as a goroutine

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL