Skip to content

Configuration ​

Settings live in two places: chanx.Config, for the whole engine, and route options, passed to Handle for one route. A route option overrides the engine's setting.

go
engine := chanx.New(chanx.Config{
	Layers:         layers.Set{"default": redisLayer},
	SendCompletion: true,
	Logger:         slog.New(slog.NewJSONHandler(os.Stdout, nil)),
})
engine.Handle("/ws/chat/{room}", &ChatConsumer{}, chanx.Name("chat"), chanx.Sequential())

Engine ​

chanx.ConfigPython settingDefaultDoes
LayersCHANNEL_LAYERSone in-memory layerchannel layers by alias
CamelizeCAMELIZEoffsnake_case in, camelCase out, on the wire
SendCompletionSEND_COMPLETIONoffcomplete, event_complete, group_complete frames
LogMessages, LogIgnoredLOG_WEBSOCKET_MESSAGE, LOG_IGNORED_ACTIONSofflog frames in and out, but these actions
Loggerslog.Default()where logs go, with conn_id and action attached
OnValidationError, OnHandlerError, OnEventErrorerror framesengine-wide error hooks; a consumer's own win
RejectBeforeUpgradeoffauthenticate before the upgrade, answer an HTTP status
MaxInFlightunlimitedframes handled at once, per connection
MaxFrameSize16 MiBa larger incoming frame closes with 1009
OutboxSize256frames queued for a connection's writer
WriteTimeout10show long a send waits on a full outbox before closing with 1013
DisconnectTimeout5show long cleanup waits for running handlers

The last four have no Python equivalent: there, the ASGI server bounds frames and slow clients. In Go, a client that stops reading cannot grow a server's memory: its outbox fills, a send waits WriteTimeout, and the connection closes with 1013.

Routes ​

OptionDoes
chanx.Name("chat")the AsyncAPI channel name; the type name without Consumer, in snake case, by default
chanx.Description("..."), chanx.Tags("a", "b")the channel's description and tags (Python's @channel)
chanx.Layer("alias")the layer the route broadcasts on
chanx.SendCompletion(bool), chanx.Camelize(bool)override the engine's
chanx.Sequential()one frame at a time, in arrival order
chanx.MaxInFlight(n)override the engine's
chanx.RejectBeforeUpgrade(bool)override the engine's
chanx.UserFrom(key)the user from framework middleware, see Authentication

Paths ​

Route paths use whole-segment parameters: /ws/chat/{room}, /ws/{org}/rooms/{room}. Each adapter turns them into its router's syntax (/ws/chat/:room for gin, echo and Fiber). Wildcards such as {rest...} are refused at Handle: routers name and slice them differently, so a consumer would see different values on each.

Close codes ​

CodeWhen
1000the client or a handler closed normally
1001the server is shutting down (engine.Shutdown)
1009a frame over MaxFrameSize
1011OnConnect failed, or the layer is unavailable
1013the client stopped reading
4401, 4403, 4000 + statusauthentication failed

Next: Testing.

MIT licensed