Help us shape the future of Go! Take the 2026 Go Developer Survey

socket

package
v1.3.244 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingSocketID  = errors.New("socket ID is required")
	ErrMissingNamespace = errors.New("socket namespace is required")
	ErrUnknownNamespace = errors.New("socket namespace is not registered")
)
View Source
var (
	ErrSocketClosed   = errors.New("socket is closed")
	ErrSendBufferFull = errors.New("socket send buffer is full")
)

Functions

This section is empty.

Types

type Config added in v1.3.244

type Config struct {
	WriteWait         time.Duration
	PongWait          time.Duration
	PingPeriod        time.Duration
	MaxMessageSize    int64
	ReadBufferSize    int
	WriteBufferSize   int
	SendBufferSize    int
	EnableCompression bool
	CheckOrigin       func(request *http.Request) bool
}

func DefaultConfig added in v1.3.244

func DefaultConfig() Config

type Connection

type Connection struct {
	Ws   *websocket.Conn
	Send chan []byte
}

type ConnectionOptions added in v1.3.244

type ConnectionOptions struct {
	ID                 string
	Namespace          string
	Context            context.Context
	ErrorLogger        errorlogger.ErrorLogger
	ReadMessageHandler ReadMessageHandler
	ResponseHeader     http.Header
}

type EventHandlers added in v0.5.5

type EventHandlers struct {
	RegisterHandler, UnregisterHandler func(s *Socket)
}

type NamespaceEventHandlerMap added in v0.5.5

type NamespaceEventHandlerMap map[string]*EventHandlers

type ReadMessageHandler added in v1.3.244

type ReadMessageHandler func(socket *Socket, rawData []byte)

type Registry

type Registry struct {
	Sockets          *sync.Map
	ServiceGoroutine goroutine.IGoroutine
	// contains filtered or unexported fields
}

func NewSocketRegistry added in v0.8.78

func NewSocketRegistry(eventHandlersMap NamespaceEventHandlerMap, serviceGoroutine goroutine.IGoroutine) *Registry

func NewSocketRegistryWithConfig added in v1.3.244

func NewSocketRegistryWithConfig(
	eventHandlersMap NamespaceEventHandlerMap,
	serviceGoroutine goroutine.IGoroutine,
	config Config,
) *Registry

func (*Registry) Close added in v1.3.244

func (registry *Registry) Close(socketID string) bool

func (*Registry) Emit added in v1.3.244

func (registry *Registry) Emit(socketID string, dto interface{}) error

func (*Registry) ServeHTTP added in v1.3.244

func (registry *Registry) ServeHTTP(
	writer http.ResponseWriter,
	request *http.Request,
	options ConnectionOptions,
) error

ServeHTTP upgrades and owns the connection until it is closed. Authentication must be completed by the caller before this method is invoked.

type Socket

type Socket struct {
	Ctx         context.Context
	ErrorLogger errorlogger.ErrorLogger
	Connection  *Connection
	ID          string
	Namespace   string
	// contains filtered or unexported fields
}

func (*Socket) Close added in v1.3.244

func (s *Socket) Close()

func (*Socket) Done added in v1.3.244

func (s *Socket) Done() <-chan struct{}

func (*Socket) Emit

func (s *Socket) Emit(dto interface{}) error

Jump to

Keyboard shortcuts

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