13 Commits

Author SHA1 Message Date
savinmax
8eaba398dc feat(hub): update register/unregister to use Inc/Dec metrics and add room-aware tests
- Change ConnectedClients metrics from Set() to Inc()/Dec() pattern
  for cleaner, atomic metric updates in register/unregister/broadcast
- Add room info to unregister and broadcast-cleanup log messages
- Handle unregistered connections gracefully (close without panic)
- Capture count inside lock for accurate log output

Tests added:
- TestRegisterClient: verifies ClientCount/RoomCount after connect
- TestUnregisterClient: verifies cleanup after disconnect
- TestRegisterMultipleRooms: verifies multi-room state tracking
- TestUnregisterCleansUpEmptyRoom: verifies empty room deletion
- TestUnregisterUnknownConnNoPanic: verifies no panic on unknown conn

All tests pass including race detector.

🤖 Assisted by the code-assist SOP
2026-06-13 13:14:57 +02:00
savinmax
03f379c73c refactor(hub): introduce room types and update Hub struct
- Add client struct with conn and room fields
- Add broadcastMsg struct with room and data fields
- Change Hub.clients to Hub.rooms map[string]map[*websocket.Conn]bool
- Add Hub.connRoom map[*websocket.Conn]string for reverse lookup
- Change broadcast channel type to chan broadcastMsg
- Change register channel type to chan client
- Update New() to initialize rooms and connRoom maps
- Update ClientCount() to use len(h.connRoom)
- Add RoomCount() method
- Update Run() loop for room-segmented register/unregister/broadcast
- Update HandleWebSocket to extract room from query param
- Backward compatible: clients without ?room use default empty room
- Update TestNew to verify rooms and connRoom maps initialized
- Add TestRoomCount to verify initial room count is 0
- Fix TestBroadcastChannel to use broadcastMsg type

All existing unit and integration tests pass (16 hub tests + 21 other).

🤖 Assisted by the code-assist SOP
2026-06-13 13:09:25 +02:00
savinmax
a40d16dae0 docs: update README with logging configuration section
Some checks failed
CI / test (push) Successful in 9s
CI / lint (push) Failing after 10s
Add documentation for the new logging config options (output and level),
including usage examples, field reference table, and updated project
structure listing the internal/logging package.
2026-06-11 19:23:05 +02:00
savinmax
3d14b7fcb8 feat(logging): add configurable log output and log level support
Add a 'logging' section to config.yaml supporting:
- output: stderr (default), stdout, or a file path
- level: debug, info, warn, error (default: info)

Implementation:
- New internal/logging package with Setup() for output destination
  and Logger struct with level-aware Debug/Info/Warn/Error methods
- Config struct extended with Logging section (output + level fields)
- Hub refactored to accept *logging.Logger via constructor injection
- main.go initializes logging early after config load

The leveled logger suppresses messages below the configured threshold
while maintaining the stdlib log format. File output uses append mode
with 0644 permissions for safe log rotation.

🤖 Assisted by the code-assist SOP
2026-06-11 19:21:20 +02:00
savinmax
905c241daa Improve reliability, testing, and documentation
Some checks failed
CI / test (push) Successful in 54s
CI / lint (push) Failing after 3m16s
- Fix metrics: change MessagesTotal, ConnectionsTotal, DisconnectionsTotal
  from Gauge to Counter with proper _total naming convention
- Fix broadcast write-error handling: failed clients now get properly
  removed with accurate metrics updates
- Add graceful shutdown: SIGINT/SIGTERM handling with 10s timeout,
  CloseGoingAway frame sent to clients before disconnect
- Add integration tests: 11 tests using real WebSocket connections
  covering connect, broadcast, disconnect, concurrency, and shutdown
- Fix example client port: changed from 8000 to 8443 to match config
- Rewrite README.md to reflect current features and usage
- Add AGENTS.md and .agents/summary/ documentation for AI assistants
2026-06-11 19:14:19 +02:00
savinmax
f69355d69d small fix
All checks were successful
CI / test (push) Successful in 10s
CI / lint (push) Successful in 11s
2025-08-04 11:11:10 +02:00
savinmax
9ad38190a5 adding config-file arg
All checks were successful
Release / release (push) Successful in 19s
CI / test (push) Successful in 9s
CI / lint (push) Successful in 12s
v0.1.0
2025-08-02 21:31:35 +02:00
savinmax
983c4195e0 Metrics config example
All checks were successful
CI / test (push) Successful in 9s
CI / lint (push) Successful in 11s
2025-08-02 21:07:26 +02:00
savinmax
e4abd6e0a7 fix release
All checks were successful
Release / release (push) Successful in 14s
v0.0.6
2025-08-02 21:00:28 +02:00
savinmax
ef3539fd31 Publishing release
All checks were successful
Release / release (push) Successful in 15s
v0.0.5
2025-08-02 19:36:14 +02:00
savinmax
dc642b93c6 another action
All checks were successful
CI / test (push) Successful in 8s
CI / lint (push) Successful in 10s
Release / release (push) Successful in 28s
v0.0.4
2025-08-02 19:22:39 +02:00
savinmax
705b6a8e6a another uses
Some checks failed
CI / test (push) Successful in 8s
CI / lint (push) Successful in 10s
Release / release (push) Failing after 22s
v0.0.2 v0.0.3
2025-08-02 19:19:13 +02:00
savinmax
e4523df602 Init
Some checks failed
CI / test (push) Successful in 1m10s
CI / lint (push) Successful in 30s
Release / release (push) Failing after 31s
0.0.1 v0.0.1
2025-08-02 18:33:50 +02:00