Documentation
¶
Index ¶
- func Accept(w http.ResponseWriter, r *http.Request, checkOrigin func(*http.Request) bool) (*websocket.Conn, error)
- func CountWorkerGoroutines() int
- func ForwardLines(ctx context.Context, hub *Hub, lines <-chan string)
- func ForwardLogJSON(ctx context.Context, hub *Hub, logs <-chan LogMessage)
- func ForwardLogJSONBatched(ctx context.Context, hub *Hub, logs <-chan LogMessage, maxBatch int, ...)
- func IsExpectedClose(err error) bool
- func NormalizeContainerLine(raw string) (level string, msg string, timestamp string)
- func NormalizeProjectLine(raw string) (level, service, msg, timestamp string)
- func NowRFC3339() string
- func ProxyHTTP(w http.ResponseWriter, r *http.Request, remoteWS string, header http.Header, ...) error
- func ServeClientWithOnRemove(ctx context.Context, hub *Hub, conn *websocket.Conn, onRemove func()) bool
- type Client
- type Hub
- type LogMessage
- type WebSocketMetrics
- func (m *WebSocketMetrics) Connections() []systemtypes.WebSocketConnectionInfo
- func (m *WebSocketMetrics) RegisterConnection(info systemtypes.WebSocketConnectionInfo) string
- func (m *WebSocketMetrics) Snapshot() systemtypes.WebSocketMetricsSnapshot
- func (m *WebSocketMetrics) UnregisterConnection(id string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accept ¶ added in v2.7.0
func Accept(w http.ResponseWriter, r *http.Request, checkOrigin func(*http.Request) bool) (*websocket.Conn, error)
Accept validates the request Origin with checkOrigin and upgrades it to a WebSocket. The origin check is the CSRF barrier for cookie-authenticated upgrades; a nil checkOrigin skips it and must only be used for endpoints authenticated by tokens or mTLS rather than browser cookies.
func CountWorkerGoroutines ¶
func CountWorkerGoroutines() int
CountWorkerGoroutines returns the number of websocket worker goroutines belonging to this package. Intended for diagnostics endpoints only.
func ForwardLines ¶
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 IsExpectedClose ¶ added in v2.7.0
IsExpectedClose reports whether err is a WebSocket close error carrying one of the benign statuses peers send on ordinary disconnect.
func NormalizeContainerLine ¶
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 ¶
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, checkOrigin func(*http.Request) bool) error
ProxyHTTP upgrades the incoming client connection and bridges it to remoteWS.
checkOrigin must be the same Origin validator the local WebSocket endpoints use. It is required: this upgrade is reached with the caller's session cookie already validated, so accepting any Origin would let an attacker-controlled page open a terminal or log stream in a remote environment.
func ServeClientWithOnRemove ¶
func ServeClientWithOnRemove(ctx context.Context, hub *Hub, conn *websocket.Conn, onRemove func()) bool
ServeClientWithOnRemove registers the client with the hub and starts read/write pumps. Caller is responsible for creating/closing the websocket.Conn. If onRemove is non-nil, it is invoked when the client is removed from the hub.
It reports whether registration succeeded. Registration fails when the hub's Run has already exited (or ctx is done) — landing on that boundary used to block forever on the unbuffered register channel, leaking the caller's goroutine and the socket. On failure nothing is registered and onRemove is never invoked, so the caller can retry against a fresh hub with the same connection, or close it and release its own bookkeeping.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a single WebSocket connection.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
func (*Hub) SetOnActive ¶
func (h *Hub) SetOnActive(fn func())
func (*Hub) SetOnEmpty ¶
func (h *Hub) SetOnEmpty(fn func())
func (*Hub) SetOnFirstClient ¶
func (h *Hub) SetOnFirstClient(fn func())
type LogMessage ¶
type WebSocketMetrics ¶ added in v2.1.0
type WebSocketMetrics struct {
// contains filtered or unexported fields
}
WebSocketMetrics tracks active WebSocket connections and their counts.
func NewWebSocketMetrics ¶ added in v2.1.0
func NewWebSocketMetrics() *WebSocketMetrics
NewWebSocketMetrics creates a new WebSocketMetrics instance.
func (*WebSocketMetrics) Connections ¶ added in v2.1.0
func (m *WebSocketMetrics) Connections() []systemtypes.WebSocketConnectionInfo
Connections returns a snapshot of all tracked WebSocket connections.
func (*WebSocketMetrics) RegisterConnection ¶ added in v2.1.0
func (m *WebSocketMetrics) RegisterConnection(info systemtypes.WebSocketConnectionInfo) string
RegisterConnection adds a connection to the tracker and increments the appropriate kind counter. Returns the assigned connection ID.
func (*WebSocketMetrics) Snapshot ¶ added in v2.1.0
func (m *WebSocketMetrics) Snapshot() systemtypes.WebSocketMetricsSnapshot
Snapshot returns a point-in-time copy of the active connection counts.
func (*WebSocketMetrics) UnregisterConnection ¶ added in v2.1.0
func (m *WebSocketMetrics) UnregisterConnection(id string)
UnregisterConnection removes a connection from the tracker and decrements the appropriate kind counter.