ws

package
v1.15.3 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountWorkerGoroutines

func CountWorkerGoroutines() int

CountWorkerGoroutines returns a best-effort count of websocket worker goroutines belonging to this package. Intended for diagnostics endpoints only.

func ForwardLines

func ForwardLines(ctx context.Context, hub *Hub, lines <-chan string)

ForwardLines forwards plain text lines to the hub.

func ForwardLogJSON

func ForwardLogJSON(ctx context.Context, hub *Hub, logs <-chan LogMessage)

ForwardLogJSON sends each LogMessage as its own JSON object frame.

func ForwardLogJSONBatched

func ForwardLogJSONBatched(ctx context.Context, hub *Hub, logs <-chan LogMessage, maxBatch int, flushInterval time.Duration)

ForwardLogJSONBatched batches log messages into a JSON array frame to reduce frame count. Flushes when maxBatch reached or flushInterval elapsed.

func NormalizeContainerLine

func NormalizeContainerLine(raw string) (level string, msg string, timestamp string)

NormalizeContainerLine parses a raw container log line into level + cleaned message. It extracts Docker's timestamp if present (when timestamps=true in Docker API).

func NormalizeProjectLine

func NormalizeProjectLine(raw string) (level, service, msg, timestamp string)

NormalizeProjectLine additionally extracts service (pattern: service | message). Returns level, service, message, timestamp (RFC3339Nano) — timestamp may be empty.

func NowRFC3339

func NowRFC3339() string

func ProxyHTTP

func ProxyHTTP(w http.ResponseWriter, r *http.Request, remoteWS string, header http.Header) error

ProxyHTTP upgrades the incoming client connection and bridges it to remoteWS.

func ServeClient

func ServeClient(ctx context.Context, hub *Hub, conn *websocket.Conn)

ServeClient registers the client with the hub and starts read/write pumps. Caller is responsible for creating/closing the websocket.Conn.

Types

type Client

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

Client represents a single WebSocket connection.

func NewClient

func NewClient(conn *websocket.Conn, sendBuffer int) *Client

type Hub

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

func NewHub

func NewHub(buffer int) *Hub

func (*Hub) Broadcast

func (h *Hub) Broadcast(msg []byte)

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

func (*Hub) Run

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

func (*Hub) SetOnEmpty

func (h *Hub) SetOnEmpty(fn func())

type LogMessage

type LogMessage struct {
	Seq         uint64 `json:"seq"`
	Level       string `json:"level,omitempty"`
	Message     string `json:"message"`
	Timestamp   string `json:"timestamp"` // RFC3339(9) string
	Service     string `json:"service,omitempty"`
	ContainerID string `json:"containerId,omitempty"`
}

Jump to

Keyboard shortcuts

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