Help us shape the future of Go! Take the 2026 Go Developer Survey

websocket

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Broadcast

func Broadcast(message []byte)

Broadcast sends a message to WebSocket clients. If the JSON has a {type, id} envelope, it delivers only to clients whose subscriptions match that (type,id). If it does not, it delivers to all (backward compatibility).

func EmitWS

func EmitWS(evType string, id int32, action string, payload interface{})

func Handler

func Handler(w http.ResponseWriter, r *http.Request)

Handler to be used in ServeMux

Types

type Client

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

type Message

type Message struct {
	Type  string  `json:"type"`            // "ping" | "subscribe" | "unsubscribe"
	Event string  `json:"event,omitempty"` // event type, e.g., "step-stats"
	Ids   []int32 `json:"ids,omitempty"`   // subscribed ids; empty slice means "all ids for this event"
}

Message represents the structure of incoming messages

type OutEvent

type OutEvent struct {
	Type string `json:"type,omitempty"` // e.g., "step-stats"
	Id   int32  `json:"id,omitempty"`   // e.g., workflow id
}

OutEvent is the minimal envelope we inspect in outgoing messages. Server should always set an event Type and a single Id for routing.

type WSEvent

type WSEvent struct {
	EventId uint64      `json:"event_id"`          // monotonic, filled by EmitWS
	Type    string      `json:"type"`              // entity: "task","worker","workflow","step","job","user"
	Id      int32       `json:"id,omitempty"`      // optional: present for single-entity events
	Action  string      `json:"action,omitempty"`  // e.g., "created","updated","deleted","status"
	Payload interface{} `json:"payload,omitempty"` // additional data
}

WS event envelope and helper. Every emitted message carries a monotonically-increasing EventId so a client that reconnects after a dropped WebSocket can ask for replay via ?since=<lastEventId>. Without this the UI would silently miss a status flip and stay stale until a full page refresh (the source of the "compile appears done before hermes finishes" symptom on 2026-09-21).

Jump to

Keyboard shortcuts

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