adapter

package
v3.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package adapter provides configuration options for the MongoDB-based Socket.IO adapter.

Package adapter defines types and interfaces for the MongoDB-based Socket.IO adapter implementation. It uses MongoDB Change Streams for inter-node communication in a clustered Socket.IO environment.

Package adapter provides a MongoDB-based adapter implementation for Socket.IO clustering. It uses MongoDB Change Streams for pub/sub communication between nodes. The document format is compatible with the Node.js @socket.io/mongo-adapter package, allowing mixed Go and Node.js deployments.

Index

Constants

View Source
const (
	// DefaultHeartbeatInterval is the default interval between heartbeats.
	DefaultHeartbeatInterval = 5_000 * time.Millisecond

	// DefaultHeartbeatTimeout is the default timeout for heartbeat responses.
	DefaultHeartbeatTimeout int64 = 10_000
)

Default configuration values for MongoAdapterOptions.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastAck

type BroadcastAck = adapter.BroadcastAck

BroadcastAck is an alias for adapter.BroadcastAck.

type BroadcastClientCount

type BroadcastClientCount = adapter.BroadcastClientCount

BroadcastClientCount is an alias for adapter.BroadcastClientCount.

type BroadcastMessage

type BroadcastMessage = adapter.BroadcastMessage

BroadcastMessage is an alias for adapter.BroadcastMessage.

type ClusterMessage

type ClusterMessage = adapter.ClusterMessage

ClusterMessage is an alias for adapter.ClusterMessage.

type ClusterResponse

type ClusterResponse = adapter.ClusterResponse

ClusterResponse is an alias for adapter.ClusterResponse.

type DisconnectSocketsMessage

type DisconnectSocketsMessage = adapter.DisconnectSocketsMessage

DisconnectSocketsMessage is an alias for adapter.DisconnectSocketsMessage.

type FetchSocketsMessage

type FetchSocketsMessage = adapter.FetchSocketsMessage

FetchSocketsMessage is an alias for adapter.FetchSocketsMessage.

type FetchSocketsResponse

type FetchSocketsResponse = adapter.FetchSocketsResponse

FetchSocketsResponse is an alias for adapter.FetchSocketsResponse.

type MongoAdapter

type MongoAdapter interface {
	adapter.ClusterAdapterWithHeartbeat

	// SetMongo configures the MongoDB client for the adapter.
	SetMongo(*mongo.MongoClient)

	// Cleanup registers a cleanup callback to be called when the adapter is closed.
	Cleanup(func())

	// OnEvent processes a change stream document from MongoDB.
	OnEvent(document *mongo.AdapterEvent)
}

MongoAdapter defines the interface for a MongoDB-based Socket.IO adapter. It extends ClusterAdapterWithHeartbeat with MongoDB-specific functionality.

func MakeMongoAdapter

func MakeMongoAdapter() MongoAdapter

MakeMongoAdapter creates a new uninitialized mongoAdapter. Call Construct() to complete initialization before use.

func NewMongoAdapter

func NewMongoAdapter(nsp socket.Namespace, client *mongo.MongoClient, opts any) MongoAdapter

NewMongoAdapter creates and initializes a new MongoDB adapter. This is the preferred way to create a MongoDB adapter instance.

type MongoAdapterBuilder

type MongoAdapterBuilder struct {
	// Mongo is the MongoDB client used for operations.
	Mongo *mongo.MongoClient
	// Opts contains configuration options for the adapter.
	Opts MongoAdapterOptionsInterface
	// contains filtered or unexported fields
}

MongoAdapterBuilder creates MongoDB adapters for Socket.IO namespaces. It manages the shared Change Stream connection across all namespace adapters.

func (*MongoAdapterBuilder) New

New creates a new MongoAdapter for the given namespace. This method implements the socket.AdapterBuilder interface.

type MongoAdapterOptions

type MongoAdapterOptions struct {
	adapter.ClusterAdapterOptions
	// contains filtered or unexported fields
}

MongoAdapterOptions holds configuration for the MongoDB adapter.

Fields:

  • addCreatedAtField: Whether to add a createdAt field to each MongoDB document. Required when using a TTL index instead of a capped collection. Default: false.
  • errorHandler: Custom error handler callback. Default: nil (errors are logged via debug).

func DefaultMongoAdapterOptions

func DefaultMongoAdapterOptions() *MongoAdapterOptions

DefaultMongoAdapterOptions returns a new MongoAdapterOptions with default values.

func (*MongoAdapterOptions) AddCreatedAtField

func (s *MongoAdapterOptions) AddCreatedAtField() bool

AddCreatedAtField returns the configured addCreatedAtField value. Returns false if not set.

func (*MongoAdapterOptions) Assign

Assign copies non-nil fields from another MongoAdapterOptionsInterface. This method is useful for merging user-provided options with defaults.

func (*MongoAdapterOptions) ErrorHandler

func (s *MongoAdapterOptions) ErrorHandler() func(error)

ErrorHandler returns the configured error handler callback, or nil if not set.

func (*MongoAdapterOptions) GetRawAddCreatedAtField

func (s *MongoAdapterOptions) GetRawAddCreatedAtField() types.Optional[bool]

GetRawAddCreatedAtField returns the raw Optional value for addCreatedAtField.

func (*MongoAdapterOptions) GetRawErrorHandler

func (s *MongoAdapterOptions) GetRawErrorHandler() types.Optional[func(error)]

GetRawErrorHandler returns the raw Optional value for errorHandler.

func (*MongoAdapterOptions) SetAddCreatedAtField

func (s *MongoAdapterOptions) SetAddCreatedAtField(v bool)

SetAddCreatedAtField sets whether to add a createdAt field to documents.

func (*MongoAdapterOptions) SetErrorHandler

func (s *MongoAdapterOptions) SetErrorHandler(handler func(error))

SetErrorHandler sets the error handler callback.

type MongoAdapterOptionsInterface

type MongoAdapterOptionsInterface interface {
	adapter.ClusterAdapterOptionsInterface

	SetAddCreatedAtField(bool)
	GetRawAddCreatedAtField() types.Optional[bool]
	AddCreatedAtField() bool

	SetErrorHandler(func(error))
	GetRawErrorHandler() types.Optional[func(error)]
	ErrorHandler() func(error)
}

MongoAdapterOptionsInterface defines the interface for configuring MongoAdapterOptions. It extends ClusterAdapterOptionsInterface with adapter-specific settings.

type ServerSideEmitMessage

type ServerSideEmitMessage = adapter.ServerSideEmitMessage

ServerSideEmitMessage is an alias for adapter.ServerSideEmitMessage.

type ServerSideEmitResponse

type ServerSideEmitResponse = adapter.ServerSideEmitResponse

ServerSideEmitResponse is an alias for adapter.ServerSideEmitResponse.

type SocketsJoinLeaveMessage

type SocketsJoinLeaveMessage = adapter.SocketsJoinLeaveMessage

SocketsJoinLeaveMessage is an alias for adapter.SocketsJoinLeaveMessage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL