Rocket Cat is a small Go WebSocket action framework built around explicit routes:
route = (cmd << 16) | subCmd
The project favors simple module boundaries, explicit registration, unified request binding, and unified responses.
/ws
bind.go
context.go
packet.go
response.go
router.go
server.go
session.go
/modules
/user
cmd.go
model.go
handler.go
service.go
/chat
cmd.go
model.go
handler.go
service.go
/room
cmd.go
model.go
handler.go
service.go
/main.go
go run .The WebSocket endpoint is:
ws://localhost:10100/ws
Open examples/ws-client.html in a browser after starting the server. It uses Vue from a CDN and can simulate user, chat, and room packets.
Rules for maintaining example pages are documented in docs/ws-client-rules.md.
Open examples/frame-sync.html in two browser windows to simulate frame synchronization. Confirm different IDs, join matching from both windows, and the room will start syncing after two clients are matched.
Requests use JSON:
{
"cmd": 1001,
"subCmd": 1,
"data": {
"account": "demo",
"password": "123456"
}
}Responses use:
{
"cmd": 1001,
"subCmd": 1,
"code": 0,
"msg": "ok",
"data": {}
}Each module must contain:
cmd.go command and route definitions only
model.go request and response structs only
handler.go bind request, call service, return response
service.go core business logic only
Handlers should use ws.Bind[T](ctx) instead of calling json.Unmarshal directly.
Modules register routes explicitly:
func Register(router *ws.Router) {
router.Register(Cmd, Login, LoginHandler)
}func LoginHandler(ctx *ws.Context) {
req, err := ws.Bind[LoginReq](ctx)
if err != nil {
return
}
resp, err := LoginService(req)
if err != nil {
ws.Fail(ctx, 1, err.Error())
return
}
ws.OK(ctx, resp)
}go test ./...