Versions in this module Expand all Collapse all v0 v0.1.0 Mar 28, 2026 Changes in this version + const CodeBadRequest + const CodeForbidden + const CodeInternalError + const CodeInvalidCodec + const CodeMessageTooLarge + const CodeNotFound + const CodeOK + const CodeProtocolError + const CodeServiceUnavail + const CodeSessionExpired + const CodeShuttingDown + const CodeStreamLimit + const CodeTimeout + const CodeTooManyRequests + const CodeUnauthorized + const DefaultKeepAliveInterval + const MaxDatagramSize + const MaxMessageSize + const Version + func AltSvcHeader(port int) string + func AltSvcMiddleware(port int) func(http.Handler) http.Handler + func CallTyped[T any](c *RPCClient, method string, params any) (T, error) + func CertFingerprint(certDER []byte) string + func Datagrams(c *Context) iter.Seq[[]byte] + func DebugMux(s *Server) *http.ServeMux + func DecodeBatch(data []byte) [][]byte + func DefaultErrorPage(w http.ResponseWriter, _ *http.Request, code int, msg string) + func HTMLErrorPage(w http.ResponseWriter, _ *http.Request, code int, msg string) + func Hash(data []byte) string + func IsConnectionError(err error) bool + func IsMessageError(err error) bool + func IsSessionClosed(err error) bool + func IsStreamClosed(err error) bool + func IsUpgradeError(err error) bool + func JoinPath(segments ...string) string + func KeepAlive(c *Context, interval time.Duration) func() + func ListenAndServeWithGracefulShutdown(s *Server, drainTimeout time.Duration) error + func Messages(s *Stream) iter.Seq[[]byte] + func Must[T any](val T, err error) T + func PProfMux() *http.ServeMux + func Pipe(a, b *Stream) error + func PipeRaw(rw io.ReadWriteCloser, s *Stream) error + func RequiredFields(v any, fields ...string) error + func Retry(ctx context.Context, cfg RetryConfig, fn func() error) error + func ServerInfo() map[string]string + func SetAltSvcHeader(w http.ResponseWriter, port int) + func Streams(c *Context) iter.Seq[*Stream] + func ValidateDatagramSize(data []byte) error + func ValidateMessage(msg any) error + type BackpressureWriter struct + func NewBackpressureWriter(s *Stream, bufferSize int) *BackpressureWriter + func (bw *BackpressureWriter) BufferUsage() float64 + func (bw *BackpressureWriter) Close() + func (bw *BackpressureWriter) IsFull() bool + func (bw *BackpressureWriter) Send(msg []byte) bool + func (bw *BackpressureWriter) Stats() (sent, dropped uint64) + type BatcherOption func(*DatagramBatcher) + func WithBatchEncoder(fn func(batch [][]byte) []byte) BatcherOption + func WithBatchInterval(d time.Duration) BatcherOption + func WithBatchSize(n int) BatcherOption + type BufferedReader struct + func NewBufferedReader(s *Stream, bufSize int) *BufferedReader + func (br *BufferedReader) ReadBuffered() ([]byte, error) + type CertRotator struct + func NewCertRotator(certFile, keyFile string, opts ...RotatorOption) (*CertRotator, error) + func (cr *CertRotator) GetCertificate(*tls.ClientHelloInfo) (*tls.Certificate, error) + func (cr *CertRotator) Stop() + func (cr *CertRotator) TLSConfig() *tls.Config + type CompressedStream struct + func NewCompressedStream(s *Stream, threshold int) *CompressedStream + func (cs *CompressedStream) ReadMessage() ([]byte, error) + func (cs *CompressedStream) WriteMessage(data []byte) error + type CompressionStats struct + CompressedBytes int64 + MessagesGzip int64 + MessagesRaw int64 + RawBytes int64 + func (cs CompressionStats) Ratio() float64 + type ConnInfo struct + ConnectedAt time.Time + LocalAddr string + Origin string + Params map[string]string + Path string + RemoteAddr string + SessionID string + Transport string + UserAgent string + type ConnectionError struct + Addr string + Op string + Wrapped error + func (e *ConnectionError) Error() string + func (e *ConnectionError) Unwrap() error + type Context struct + func (c *Context) AcceptStream() (*Stream, error) + func (c *Context) AcceptUniStream() (*ReceiveStream, error) + func (c *Context) Close() error + func (c *Context) CloseWithError(code uint32, msg string) error + func (c *Context) Context() context.Context + func (c *Context) Get(key string) (any, bool) + func (c *Context) GetString(key string) string + func (c *Context) ID() string + func (c *Context) Info() ConnInfo + func (c *Context) InfoJSON() string + func (c *Context) LocalAddr() net.Addr + func (c *Context) MustGet(key string) any + func (c *Context) OpenStream() (*Stream, error) + func (c *Context) OpenStreamSync() (*Stream, error) + func (c *Context) OpenUniStream() (*SendStream, error) + func (c *Context) Param(name string) string + func (c *Context) Params() map[string]string + func (c *Context) ReceiveDatagram() ([]byte, error) + func (c *Context) ReceiveDatagramContext(ctx context.Context) ([]byte, error) + func (c *Context) RemoteAddr() net.Addr + func (c *Context) Request() *http.Request + func (c *Context) SendDatagram(data []byte) error + func (c *Context) SendDatagramSafe(data []byte) error + func (c *Context) Server() *Server + func (c *Context) Session() *webtransport.Session + func (c *Context) Set(key string, value any) + type ContextStream struct + func (cs *ContextStream) Close() error + func (cs *ContextStream) Context() context.Context + func (cs *ContextStream) ReadMessageContext() ([]byte, error) + func (cs *ContextStream) WriteMessageContext(data []byte) error + type DatagramBatcher struct + func NewDatagramBatcher(c *Context, opts ...BatcherOption) *DatagramBatcher + func (b *DatagramBatcher) Add(data []byte) + func (b *DatagramBatcher) Close() + func (b *DatagramBatcher) Flush() + type ErrorPageHandler func(w http.ResponseWriter, r *http.Request, code int, msg string) + type ErrorResponse struct + Code int + Error string + Message string + type Event struct + Room string + Session *Context + Type EventType + type EventBus struct + func NewEventBus() *EventBus + func (eb *EventBus) Emit(event Event) + func (eb *EventBus) EmitAsync(event Event) + func (eb *EventBus) On(eventType EventType, handler EventHandler) + type EventHandler func(Event) + type EventType int + const EventConnect + const EventDisconnect + const EventJoinRoom + const EventLeaveRoom + func (e EventType) String() string + type FlowControlMonitor struct + BytesReceived atomic.Int64 + BytesSent atomic.Int64 + DatagramsRecvd atomic.Int64 + DatagramsSent atomic.Int64 + StreamsClosed atomic.Int64 + StreamsOpened atomic.Int64 + WriteBlocks atomic.Int64 + func NewFlowControlMonitor() *FlowControlMonitor + func (fc *FlowControlMonitor) Stats() FlowStats + type FlowStats struct + BytesReceived int64 + BytesSent int64 + DatagramsRecvd int64 + DatagramsSent int64 + StreamsActive int64 + StreamsClosed int64 + StreamsOpened int64 + WriteBlocks int64 + type Group struct + func (g *Group) Handle(pattern string, handler HandlerFunc, mw ...MiddlewareFunc) + func (g *Group) Use(mw ...MiddlewareFunc) + type HandlerFunc func(*Context) + func HandleBoth(streamFn StreamHandler, datagramFn func([]byte, *Context) []byte) HandlerFunc + func HandleDatagram(fn func(data []byte, c *Context) []byte) HandlerFunc + func HandleStream(fn StreamHandler) HandlerFunc + type HealthCheck struct + func NewHealthCheck(s *Server) *HealthCheck + func (h *HealthCheck) Handler() http.Handler + func (h *HealthCheck) ServeHTTP(w http.ResponseWriter, r *http.Request) + type HealthResponse struct + ActiveSessions int + Status string + Transport string + Uptime string + type InterceptedStream struct + func Intercept(s *Stream, opts ...InterceptorOption) *InterceptedStream + func (is *InterceptedStream) ReadMessage() ([]byte, error) + func (is *InterceptedStream) WriteMessage(data []byte) error + type InterceptorOption func(*StreamInterceptor) + func OnRead(fn func(data []byte) ([]byte, error)) InterceptorOption + func OnWrite(fn func(data []byte) ([]byte, error)) InterceptorOption + type KVSync struct + func NewKVSync() *KVSync + func (kv *KVSync) Delete(key string) + func (kv *KVSync) Get(key string, v any) error + func (kv *KVSync) GetRaw(key string) (json.RawMessage, bool) + func (kv *KVSync) Keys() []string + func (kv *KVSync) Len() int + func (kv *KVSync) OnChange(fn func(key string, value json.RawMessage)) + func (kv *KVSync) Set(key string, value any) error + func (kv *KVSync) Snapshot() map[string]json.RawMessage + type MessageError struct + Op string + Size int + Wrapped error + func (e *MessageError) Error() string + func (e *MessageError) Unwrap() error + type MiddlewareFunc func(c *Context, next HandlerFunc) + type MigrationEvent struct + MigratedAt time.Time + NewAddr net.Addr + OldAddr net.Addr + SessionID string + type MigrationWatcher struct + func NewMigrationWatcher(store *SessionStore, onMigrate func(MigrationEvent)) *MigrationWatcher + func (mw *MigrationWatcher) Stop() + type Option func(*Server) + func WithAddr(addr string) Option + func WithAutoCert(domain string, cacheDir string) Option + func WithAutoCertMulti(domains []string, cacheDir string) Option + func WithCertRotator(cr *CertRotator) Option + func WithCheckOrigin(fn func(r *http.Request) bool) Option + func WithIdleTimeout(d time.Duration) Option + func WithQUICConfig(cfg QUICConfig) Option + func WithSelfSignedTLS() Option + func WithTLS(certFile, keyFile string) Option + type PreflightResult struct + Issues []string + Ready bool + type PresenceInfo struct + Metadata map[string]any + SessionID string + Status string + UpdatedAt time.Time + UserID string + type PresenceTracker struct + func NewPresenceTracker() *PresenceTracker + func (pt *PresenceTracker) Count(room string) int + func (pt *PresenceTracker) GetPresence(room string) []PresenceInfo + func (pt *PresenceTracker) GetPresenceJSON(room string) []byte + func (pt *PresenceTracker) Join(room string, c *Context) + func (pt *PresenceTracker) Leave(room string, c *Context) + func (pt *PresenceTracker) OnChange(fn func(room string, info PresenceInfo, event string)) + func (pt *PresenceTracker) SetMetadata(room, sessionID string, metadata map[string]any) + func (pt *PresenceTracker) UpdateStatus(room, sessionID, status string) + type Priority int + const PriorityBackground + const PriorityCritical + const PriorityHigh + const PriorityLow + const PriorityNormal + type PubSub struct + func NewPubSub() *PubSub + func (ps *PubSub) Publish(topic string, data []byte) + func (ps *PubSub) PublishExcept(topic string, data []byte, excludeID string) + func (ps *PubSub) Subscribe(topic string, c *Context) + func (ps *PubSub) SubscriberCount(topic string) int + func (ps *PubSub) Topics() []string + func (ps *PubSub) TopicsForSession(sessionID string) []string + func (ps *PubSub) Unsubscribe(topic string, c *Context) + func (ps *PubSub) UnsubscribeAll(c *Context) + type QUICConfig struct + InitialConnectionReceiveWindow uint64 + InitialStreamReceiveWindow uint64 + MaxConnectionReceiveWindow uint64 + MaxIncomingStreams int64 + MaxIncomingUniStreams int64 + MaxStreamReceiveWindow uint64 + func DefaultQUICConfig() QUICConfig + func GameServerQUICConfig() QUICConfig + func HighThroughputQUICConfig() QUICConfig + type RPCClient struct + func NewRPCClient(s *Stream) *RPCClient + func (c *RPCClient) Call(method string, params any) (json.RawMessage, error) + func (c *RPCClient) Close() error + type RPCError struct + Code int + Message string + func (e *RPCError) Error() string + type RPCHandler func(params json.RawMessage) (any, error) + type RPCRequest struct + ID uint64 + Method string + Params json.RawMessage + type RPCResponse struct + Error *RPCError + ID uint64 + Result json.RawMessage + type RPCServer struct + func NewRPCServer() *RPCServer + func (rpc *RPCServer) Register(method string, handler RPCHandler) + func (rpc *RPCServer) Serve(s *Stream) + type ReceiveStream struct + func (s *ReceiveStream) CancelRead(code uint32) + func (s *ReceiveStream) Read(b []byte) (int, error) + func (s *ReceiveStream) ReadMessage() ([]byte, error) + func (s *ReceiveStream) SetReadDeadline(t time.Time) error + type ReliableDatagram struct + func NewReliableDatagram(c *Context, onReceive func(data []byte), opts ...ReliableOption) *ReliableDatagram + func (rd *ReliableDatagram) PendingCount() int + func (rd *ReliableDatagram) Send(data []byte) error + type ReliableOption func(*ReliableDatagram) + func WithMaxRetries(n int) ReliableOption + func WithRetryTimeout(d time.Duration) ReliableOption + type ResumeStore struct + func NewResumeStore(ttl time.Duration) *ResumeStore + func (rs *ResumeStore) Count() int + func (rs *ResumeStore) Restore(c *Context, token ResumeToken) bool + func (rs *ResumeStore) Save(c *Context) ResumeToken + type ResumeToken string + type RetryConfig struct + InitDelay time.Duration + Jitter bool + MaxAttempts int + MaxDelay time.Duration + func DefaultRetryConfig() RetryConfig + type RingBuffer struct + func NewRingBuffer[T any](capacity int) *RingBuffer[T] + func (rb *RingBuffer[T]) Cap() int + func (rb *RingBuffer[T]) Clear() + func (rb *RingBuffer[T]) Items() []T + func (rb *RingBuffer[T]) Last() (T, bool) + func (rb *RingBuffer[T]) Len() int + func (rb *RingBuffer[T]) Push(item T) + type Room struct + func (r *Room) Broadcast(data []byte) + func (r *Room) BroadcastExcept(data []byte, excludeID string) + func (r *Room) BroadcastStream(data []byte) + func (r *Room) BroadcastStreamExcept(data []byte, excludeID string) + func (r *Room) Count() int + func (r *Room) ForEach(fn func(*Context)) + func (r *Room) Join(ctx *Context) + func (r *Room) Leave(ctx *Context) + func (r *Room) Members() []*Context + func (r *Room) Name() string + func (r *Room) OnJoin(fn func(*Context)) + func (r *Room) OnLeave(fn func(*Context)) + func (r *Room) SafeBroadcast(data []byte, logger *slog.Logger) + func (r *Room) SafeBroadcastExcept(data []byte, excludeID string, logger *slog.Logger) + type RoomManager struct + func NewRoomManager() *RoomManager + func (rm *RoomManager) Get(name string) (*Room, bool) + func (rm *RoomManager) GetOrCreate(name string) *Room + func (rm *RoomManager) Remove(name string) + func (rm *RoomManager) Rooms() []string + type RoomMessage struct + Data []byte + SenderID string + Timestamp time.Time + type RoomWithHistory struct + func NewRoomWithHistory(room *Room, historySize int) *RoomWithHistory + func (r *RoomWithHistory) BroadcastAndRecord(senderID string, data []byte) + func (r *RoomWithHistory) BroadcastExceptAndRecord(senderID string, data []byte) + func (r *RoomWithHistory) ClearHistory() + func (r *RoomWithHistory) History() []RoomMessage + func (r *RoomWithHistory) HistorySize() int + func (r *RoomWithHistory) ReplayHistory(c *Context) + func (r *RoomWithHistory) ReplayHistorySince(c *Context, since time.Time) + type RotatorOption func(*CertRotator) + func WithRotationInterval(d time.Duration) RotatorOption + func WithRotationLogger(logger *slog.Logger) RotatorOption + type Route struct + Handler HandlerFunc + Middleware []MiddlewareFunc + Pattern string + type Router struct + func NewRouter() *Router + func (r *Router) Add(pattern string, handler HandlerFunc, mw ...MiddlewareFunc) + func (r *Router) ExtractParams(pattern, path string) map[string]string + func (r *Router) Match(path string) (*Route, map[string]string) + func (r *Router) Routes() []*Route + type SendStream struct + func (s *SendStream) CancelWrite(code uint32) + func (s *SendStream) Close() error + func (s *SendStream) SetWriteDeadline(t time.Time) error + func (s *SendStream) Write(b []byte) (int, error) + func (s *SendStream) WriteMessage(data []byte) error + type Server struct + func New(opts ...Option) *Server + func (s *Server) Addr() string + func (s *Server) Broadcast(data []byte) + func (s *Server) BroadcastExcept(data []byte, excludeID string) + func (s *Server) CertHash() string + func (s *Server) Close() error + func (s *Server) Group(prefix string, mw ...MiddlewareFunc) *Group + func (s *Server) Handle(pattern string, handler HandlerFunc, mw ...MiddlewareFunc) + func (s *Server) ListenAndServe() error + func (s *Server) Multicast(data []byte, filter func(*Context) bool) + func (s *Server) MulticastStream(data []byte, filter func(*Context) bool) + func (s *Server) OnConnect(fn func(*Context)) + func (s *Server) OnDisconnect(fn func(*Context)) + func (s *Server) OnShutdown(fn ShutdownHook) + func (s *Server) Preflight() []string + func (s *Server) PreflightCheck() PreflightResult + func (s *Server) SessionCount() int + func (s *Server) Sessions() *SessionStore + func (s *Server) Shutdown(ctx context.Context) error + func (s *Server) Use(mw ...MiddlewareFunc) + type SessionCloseError struct + Code uint32 + Message string + func (e *SessionCloseError) Error() string + type SessionStore struct + func NewSessionStore() *SessionStore + func (ss *SessionStore) Add(ctx *Context) + func (ss *SessionStore) Broadcast(data []byte) + func (ss *SessionStore) CloseAll() + func (ss *SessionStore) Count() int + func (ss *SessionStore) Each(fn func(*Context)) + func (ss *SessionStore) FindByValue(key string, value any) []*Context + func (ss *SessionStore) Get(id string) (*Context, bool) + func (ss *SessionStore) IDs() []string + func (ss *SessionStore) Remove(id string) + type ShutdownHook func() + type Stream struct + func OpenTypedStream(c *Context, typeID uint16) (*Stream, error) + func RetryStream(ctx context.Context, c *Context, cfg RetryConfig) (*Stream, error) + func (s *Stream) CancelRead(code uint32) + func (s *Stream) CancelWrite(code uint32) + func (s *Stream) Close() error + func (s *Stream) Raw() *webtransport.Stream + func (s *Stream) Read(b []byte) (int, error) + func (s *Stream) ReadMessage() ([]byte, error) + func (s *Stream) SessionContext() *Context + func (s *Stream) SetDeadline(t time.Time) error + func (s *Stream) SetReadDeadline(t time.Time) error + func (s *Stream) SetWriteDeadline(t time.Time) error + func (s *Stream) WithContext(ctx context.Context) *ContextStream + func (s *Stream) WithDeadline(deadline time.Time) *ContextStream + func (s *Stream) WithTimeout(d time.Duration) *ContextStream + func (s *Stream) Write(b []byte) (int, error) + func (s *Stream) WriteMessage(data []byte) error + type StreamCloseError struct + Code uint32 + Remote bool + func (e *StreamCloseError) Error() string + type StreamConfig struct + Priority Priority + TypeID uint16 + func DefaultStreamConfig() StreamConfig + type StreamHandler func(s *Stream, c *Context) + type StreamInterceptor struct + type StreamMux struct + func NewStreamMux() *StreamMux + func (m *StreamMux) Fallback(handler StreamHandler) + func (m *StreamMux) Handle(typeID uint16, handler StreamHandler) + func (m *StreamMux) Serve(c *Context) + type StreamOptions struct + MaxMessageSize int + ReadBufferSize int + WriteBufferSize int + func DefaultStreamOptions() StreamOptions + type Tags struct + func NewTags() *Tags + func (t *Tags) AllTags() []string + func (t *Tags) Count(tag string) int + func (t *Tags) HasTag(sessionID, tag string) bool + func (t *Tags) SessionsWithTag(tag string) []string + func (t *Tags) Tag(sessionID, tag string) + func (t *Tags) TagsForSession(sessionID string) []string + func (t *Tags) Untag(sessionID, tag string) + func (t *Tags) UntagAll(sessionID string) + type Ticker struct + func NewTicker(c *Context, interval time.Duration, getData func() []byte) *Ticker + func (t *Ticker) Stop() + type TypedDatagram struct + func NewTypedDatagram[T any](ctx *Context, c codec.Codec) *TypedDatagram[T] + func (td *TypedDatagram[T]) Receive() (T, error) + func (td *TypedDatagram[T]) Send(v T) error + type TypedPubSub struct + func NewTypedPubSub[T any](ps *PubSub, c codec.Codec) *TypedPubSub[T] + func (tp *TypedPubSub[T]) Publish(topic string, msg T) error + func (tp *TypedPubSub[T]) PublishExcept(topic string, msg T, excludeID string) error + func (tp *TypedPubSub[T]) Subscribe(topic string, c *Context) + func (tp *TypedPubSub[T]) Unsubscribe(topic string, c *Context) + func (tp *TypedPubSub[T]) UnsubscribeAll(c *Context) + type TypedRoom struct + func NewTypedRoom[T any](room *Room, c codec.Codec) *TypedRoom[T] + func (tr *TypedRoom[T]) Broadcast(v T) error + func (tr *TypedRoom[T]) BroadcastExcept(v T, excludeID string) error + func (tr *TypedRoom[T]) Room() *Room + type TypedStream struct + func NewTypedStream[R any, W any](s *Stream, c codec.Codec) *TypedStream[R, W] + func (ts *TypedStream[R, W]) Close() error + func (ts *TypedStream[R, W]) Read() (R, error) + func (ts *TypedStream[R, W]) Stream() *Stream + func (ts *TypedStream[R, W]) Write(v W) error + type UpgradeError struct + Message string + StatusCode int + func (e *UpgradeError) Error() string + type Validator interface + Validate func() error