Documentation
¶
Overview ¶
Package ws implements the WebSocket endpoint that streams real-time data (container stats and logs) to authenticated frontend clients.
A single connection is multiplexed: the client sends "subscribe" messages naming a channel + target, and the server pushes tagged frames back. This lets one dashboard watch many containers over one socket.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub serves WebSocket connections backed by a Streamer.
func (*Hub) Serve ¶
func (h *Hub) Serve(ctx context.Context, conn *websocket.Conn, allow func(channel string, hostID int64) bool)
Serve handles one accepted WebSocket connection until it closes. allow gates each subscription by its channel AND the host it targets: it is called with both and must return true for the stream to start (the caller maps the channel to an RBAC section and checks the user's live permissions for that host). The host matters because a subscribe frame names one — without it, a user scoped to one host could stream a container's logs from another. A nil allow permits all channels (used in tests).
type Streamer ¶
type Streamer interface {
StreamStats(ctx context.Context, hostID int64, id string, emit func(docker.StatsSample)) error
StreamLogs(ctx context.Context, hostID int64, id string, follow bool, tail string, emit func(docker.LogLine)) error
}
Streamer is the subset of the docker manager the hub needs.