websocket

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

README

websocket

import "github.com/agentstation/starmap/internal/server/websocket"

Package websocket provides WebSocket support for real-time catalog updates.

Index

type Client

Client represents a WebSocket client connection.

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

func NewClient
func NewClient(id string, hub *Hub, conn *websocket.Conn) *Client

NewClient creates a new WebSocket client.

func (*Client) ReadPump
func (c *Client) ReadPump()

ReadPump pumps messages from the WebSocket connection to the hub.

func (*Client) WritePump
func (c *Client) WritePump()

WritePump pumps messages from the hub to the WebSocket connection.

type Hub

Hub maintains active WebSocket connections and broadcasts messages.

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

func NewHub
func NewHub(logger *zerolog.Logger) *Hub

NewHub creates a new WebSocket hub.

func (*Hub) Broadcast
func (h *Hub) Broadcast(message Message)

Broadcast sends a message to all connected clients.

func (*Hub) ClientCount
func (h *Hub) ClientCount() int

ClientCount returns the number of connected clients.

func (*Hub) Register
func (h *Hub) Register(client *Client)

Register registers a client with the hub.

func (*Hub) Run
func (h *Hub) Run(ctx context.Context)

Run starts the hub's main loop. Should be called in a goroutine. The hub will run until the context is cancelled.

type Message

Message represents a WebSocket message.

type Message struct {
    Type      string    `json:"type"`
    Timestamp time.Time `json:"timestamp"`
    Data      any       `json:"data"`
}

Generated by gomarkdoc

Documentation

Overview

Package websocket provides WebSocket support for real-time catalog updates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a WebSocket client connection.

func NewClient

func NewClient(id string, hub *Hub, conn *websocket.Conn) *Client

NewClient creates a new WebSocket client.

func (*Client) ReadPump

func (c *Client) ReadPump()

ReadPump pumps messages from the WebSocket connection to the hub.

func (*Client) WritePump

func (c *Client) WritePump()

WritePump pumps messages from the hub to the WebSocket connection.

type Hub

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

Hub maintains active WebSocket connections and broadcasts messages.

func NewHub

func NewHub(logger *zerolog.Logger) *Hub

NewHub creates a new WebSocket hub.

func (*Hub) Broadcast

func (h *Hub) Broadcast(message Message)

Broadcast sends a message to all connected clients.

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount returns the number of connected clients.

func (*Hub) Register

func (h *Hub) Register(client *Client)

Register registers a client with the hub.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

Run starts the hub's main loop. Should be called in a goroutine. The hub will run until the context is cancelled.

type Message

type Message struct {
	Type      string    `json:"type"`
	Timestamp time.Time `json:"timestamp"`
	Data      any       `json:"data"`
}

Message represents a WebSocket message.

Jump to

Keyboard shortcuts

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