Skip to content

Differences from Python ​

chanx-go matches Python chanx on the wire, and a test pins each behaviour against values recorded from Python. These are the places it differs, each on purpose.

CasePython chanxchanx-go
A payload value of the wrong type that Pydantic's lax mode coerces ("3" for an int, 1 or "true" for a bool)accepted, coercedan error frame (int_type, bool_type...). Envelope ints (version, seq) stay lax on both
A text frame that is not JSONInvalid JSON: and Python's decoder messageInvalid JSON: and Go's decoder message
send_message_immediatelyyields after each sendnot needed: each connection has a writer goroutine
A client that stops readingleft to the ASGI servera bounded outbox; closed with 1013 after WriteTimeout
A huge frameleft to the ASGI server (uvicorn: 16 MiB)MaxFrameSize, 16 MiB by default; closed with 1009
Handler concurrencyone task per messageone goroutine per frame; Sequential and MaxInFlight to limit it
Redis queue layer (RedisChannelLayer)availablenot yet; the pub/sub layer only
Authentication before the upgradeafter the socket is acceptedthe same by default; RejectBeforeUpgrade answers an HTTP 401 or 403 instead of upgrading
Disconnect hookdisconnect() runs after the groups are leftOnDisconnect runs before, so it can still broadcast to them
Groups of a mixina subclass's groups replaces its parent'seach embedded struct's Groups adds to the consumer's
Broadcasting from a topic handler without naming groupsthe topic's own groups, empty unless set: nobody receives itthe connection's groups
Non-ASCII namesUnicode rules: camelize("a_ß") is "aSS", a topic parameter may be {nom_é}ASCII rules: "aß", and the pattern is refused
AsyncAPI: two schemas with one nameprefixed with the consumer's nameprefixed with the package's name
AsyncAPI: channel descriptionthe description option, else the class docstringthe Description option only: Go has no docstrings at run time
AsyncAPI: path parameter typesfrom the Django converter (int, slug...)always str: Go routes have untyped parameters
AsyncAPI: servers and security schemesin the order givensorted by name, since they come from Go maps
Generated client layouta package per channel, plus shared/ and a copied base/one package, messages.go and channels.go, on the chanxclient module
Generated names that clashthe later schema replaces the earliergeneration stops and names both
A request answered by an error framethe error frame is the replya *chanxclient.RequestError

Naming ​

PythonGo
a message class ChatMessage(BaseMessage)a struct embedding chanx.BaseMessage
@ws_handler async def handle_chata method HandleChat(ctx, ChatMessage)
@event_handlera method taking *chanx.EventContext
@channel(name=..., tags=...)chanx.Name, chanx.Tags route options
authenticator_classan Authenticate method
groups = [...]a Groups(*Conn) []string method
self.broadcast_message(m)ctx.Broadcast(m)
ChatConsumer.broadcast_event(e, groups)publisher.BroadcastEvent(ctx, e, groups...)
WebsocketCommunicatorchanxtest.Connect
capture_broadcast_eventschanxtest.Spy and chanxtest.BroadcastEvents
CHANX settingschanx.Config

MIT licensed