websocket

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

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

type Hub

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

Hub maintains active WebSocket connections and broadcasts messages

func NewHub

func NewHub() *Hub

NewHub creates a new WebSocket hub

func (*Hub) Broadcast

func (h *Hub) Broadcast(msgType string, data interface{}) error

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) Run

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

Run starts the hub's main loop

func (*Hub) ServeWS

func (h *Hub) ServeWS(w http.ResponseWriter, r *http.Request)

ServeWS handles WebSocket requests from clients

func (*Hub) ServeWSUntil

func (h *Hub) ServeWSUntil(w http.ResponseWriter, r *http.Request, expiresAt time.Time)

ServeWSUntil closes an authorized connection at its session's absolute expiry. A zero deadline is reserved for connections that do not use sessions (local demo).

type Message

type Message struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

Message types for WebSocket communication

Jump to

Keyboard shortcuts

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