WebSocket hub with channel-based pub/sub
Find a file
Snider c2145c076f
Some checks failed
Security Scan / security (push) Has been cancelled
Test / test (push) Has been cancelled
feat(go): add service.go — Core service registration (Mantis #1336)
Wires the *Hub surface into Core's service-registration plumbing
behind a *core.ServiceRuntime[HubConfig]. NewService() factory builds
the hub via NewHubWithConfig() and returns a *Service ready for
c.Service() registration.

Action handlers exposed via OnStartup:
  ws.broadcast            — opts.type/channel/process_id/data → all clients
  ws.send_channel         — opts.channel + message-shape → channel
  ws.send_event           — opts.event + opts.data
  ws.send_error           — opts.message
  ws.send_process_output  — opts.process_id + opts.output
  ws.send_process_status  — opts.process_id + opts.status + opts.exit_code
  ws.client_count         — int
  ws.channel_count        — int
  ws.subscriber_count     — opts.channel → int
  ws.stats                — HubStats

Subscribe/Unsubscribe (take *Client), HandleWebSocket / Handler (HTTP
handlers), iter.Seq accessors stay direct method calls — not IPC-friendly.

OnStartup spawns Hub.Run in a background goroutine; OnShutdown cancels
the hub context.

Note: pre-existing auth_test failures in baseline (not introduced by
this change). Service-specific tests pass.

Co-authored-by: Hephaestus <hephaestus@lthn.ai>
2026-05-01 16:26:37 +01:00
.core chore: add .core/ build and release configs 2026-03-06 18:52:37 +00:00
.forgejo/workflows ci: add Forgejo Actions test and security scan workflows 2026-02-23 03:28:08 +00:00
docs refactor(core): go-ws round 2 — full 23-dim COMPLIANT 2026-04-29 05:42:26 +01:00
external chore(repo): refresh submodules + go.work hygiene (Phase 2 cascade unblock) 2026-05-01 09:41:44 +01:00
go feat(go): add service.go — Core service registration (Mantis #1336) 2026-05-01 16:26:37 +01:00
tests/cli/ws fix(ws): address residual CodeRabbit findings on PR #3 2026-04-27 15:29:37 +01:00
.editorconfig chore: add Go repo norms (badges, contributing, lint, taskfile, editorconfig) 2026-02-23 06:45:51 +00:00
.gitignore chore: add .core/ and .idea/ to .gitignore 2026-03-15 10:17:50 +00:00
.gitmodules refactor(go): restructure to /go/ subtree (Mantis #1255) 2026-05-01 03:10:13 +01:00
.golangci.yml fix(ws): address residual CodeRabbit findings on PR #3 2026-04-27 15:29:37 +01:00
.woodpecker.yml ci: woodpecker pipeline (Go) — golangci-lint/eslint/phpstan + sonar.lthn.sh 2026-04-29 00:03:25 +01:00
AGENTS.md refactor(core): align go-ws with hardened core/go reference shape 2026-04-29 05:26:26 +01:00
CLAUDE.md chore: migrate to dappco.re vanity import path 2026-03-21 23:45:55 +00:00
CONTRIBUTING.md chore: add Go repo norms (badges, contributing, lint, taskfile, editorconfig) 2026-02-23 06:45:51 +00:00
go.work refactor(go): restructure to /go/ subtree (Mantis #1255) 2026-05-01 03:10:13 +01:00
go.work.sum Harden websocket auth and Redis startup 2026-04-15 17:54:54 +01:00
LICENCE chore: add EUPL-1.2 LICENCE file (UK English canonical) 2026-05-01 08:35:22 +01:00
README.md refactor(core): go-ws round 2 — full 23-dim COMPLIANT 2026-04-29 05:42:26 +01:00
sonar-project.properties ci: woodpecker pipeline (Go) — golangci-lint/eslint/phpstan + sonar.lthn.sh 2026-04-28 23:33:40 +01:00

Go Reference License: EUPL-1.2 Go Version

go-ws

WebSocket hub for real-time streaming in Go. Implements the hub pattern with centralised connection management, named channel pub/sub, token-based authentication on upgrade, client-side reconnection with exponential backoff, and a Redis pub/sub bridge for coordinating broadcasts across multiple hub instances. The envelope pattern with a per-bridge source ID prevents loop amplification when the Redis bridge is in use.

Module: forge.lthn.ai/core/go-ws Licence: EUPL-1.2 Language: Go 1.25

Quick Start

import "forge.lthn.ai/core/go-ws"

hub := ws.NewHub()
go hub.Run(ctx)

// Mount on any HTTP mux
http.HandleFunc("/ws", hub.Handler())

// Send process output to subscribers of "process:abc"
hub.SendProcessOutput("abc", "output line")

// Redis bridge for multi-instance coordination
bridgeResult := ws.NewRedisBridge(hub, ws.RedisConfig{Addr: "localhost:6379"})
if !bridgeResult.OK {
    return bridgeResult
}
bridge := bridgeResult.Value.(*ws.RedisBridge)
if r := bridge.Start(ctx); !r.OK {
    return r
}

Documentation

  • Architecture — hub pattern, channel subscriptions, authentication, Redis bridge, envelope loop prevention
  • Development Guide — prerequisites, test patterns, coding standards
  • Project History — completed phases with commit hashes, known limitations

Build & Test

go test ./...
go test -race ./...
go test -bench=. -benchmem ./...
go build ./...

Licence

European Union Public Licence 1.2 — see LICENCE for details.