Documentation
¶
Overview ¶
Package wsbrokerclient provides a high-performance, mTLS-enabled Go client library for WSBroker, featuring automatic reconnection, dynamic channel subscriptions, point-to-point and broadcast messaging, and RESTful management APIs.
Index ¶
- Constants
- Variables
- func RegisterPayload[T any](eventType EventType)
- func UnmarshalDynamic(raw *RawEvent) (any, error)
- type BaseEvent
- type BrokerClient
- type ChannelInfo
- type Client
- type ClientInterface
- type Config
- type ConnectionMode
- type ConnectionState
- type Event
- func NewEventTyped[T any](eventType EventType, source, target string, data T) (*Event[T], error)
- func RequestPayload[Resp any, Req any](ctx context.Context, c ClientInterface, target string, reqType event.EventType, ...) (*Event[Resp], error)
- func RequestTyped[Resp any](ctx context.Context, c ClientInterface, evt *RawEvent) (*Event[Resp], error)
- func ToTyped[T any](raw *RawEvent, expectedTypes ...EventType) (*Event[T], error)
- type EventHandler
- type EventType
- type FileMessage
- type NTPQueryOptions
- type NTPResponse
- type Option
- type PayloadUnmarshaler
- type PublishResponse
- type RESTClient
- type RESTConfig
- type RESTOption
- type RawEvent
- type Subscription
- type TypedEventHandler
- type TypedSubscription
- type UnsubscribeFunc
- func OnChannelTyped[T any](c ClientInterface, channel string, handler TypedEventHandler[T], ...) UnsubscribeFunc
- func OnEventTyped[T any](c ClientInterface, handler TypedEventHandler[T], ...) UnsubscribeFunc
- func OnTyped[T any](c ClientInterface, eventType EventType, handler TypedEventHandler[T], ...) UnsubscribeFunc
- type WSMessage
Constants ¶
const ( TypeAttach = event.TypeAttach TypeDetach = event.TypeDetach TypeMessage = event.TypeMessage TypeFile = event.TypeFile TypePing = event.TypePing TypePong = event.TypePong TypeNTPQuery = event.TypeNTPQuery TypeNTPResponse = event.TypeNTPResponse TypeNTPError = event.TypeNTPError TypeChannelInfoQuery = event.TypeChannelInfoQuery TypeChannelInfoResponse = event.TypeChannelInfoResponse TypeChannelInfoError = event.TypeChannelInfoError )
Standard EventType constants.
const ( StateDisconnected = client.StateDisconnected StateConnecting = client.StateConnecting StateConnected = client.StateConnected StateReconnecting = client.StateReconnecting StateClosed = client.StateClosed )
Standard ConnectionState constants.
Standard ConnectionMode constants.
Variables ¶
var ( WithEndpoint = client.WithEndpoint WithClientName = client.WithClientName WithInitialChannels = client.WithInitialChannels WithMode = client.WithMode WithBearerToken = client.WithBearerToken WithTLSConfig = client.WithTLSConfig WithTLSCertLoader = client.WithTLSCertLoader WithAutoReconnect = client.WithAutoReconnect WithReconnectStrategy = client.WithReconnectStrategy WithPingInterval = client.WithPingInterval WithReadLimit = client.WithReadLimit WithConnectTimeout = client.WithConnectTimeout WithWriteTimeout = client.WithWriteTimeout WithLogger = client.WithLogger )
Functional options re-exported from client package.
var ( NewEvent = event.NewEvent NewMessageEvent = event.NewMessageEvent NewRawEvent = event.NewRawEvent NewFileMessage = event.NewFileMessage NewReplyEvent = event.NewReplyEvent NewWSMessage = event.NewWSMessage GenerateEventID = event.GenerateEventID GenerateSessionID = client.GenerateSessionID RegisterPayloadFactory = event.RegisterPayloadFactory GetPayloadUnmarshaler = event.GetPayloadUnmarshaler )
Event constructors re-exported from event package.
Functions ¶
func RegisterPayload ¶
func RegisterPayload[T any](eventType EventType)
RegisterPayload associates an EventType with a concrete payload type T in the global registry.
func UnmarshalDynamic ¶
UnmarshalDynamic unmarshals a RawEvent's data payload according to the type registry.
Types ¶
type BrokerClient ¶
type BrokerClient = client.BrokerClient
BrokerClient is an alias for ClientInterface for compatibility with downstream controllers and clients.
type ChannelInfo ¶
type ChannelInfo = event.ChannelInfo
ChannelInfo holds channel subscriber and client details.
type ClientInterface ¶
type ClientInterface = client.ClientInterface
ClientInterface defines the standard interface for communicating with a WSBroker server.
type Config ¶
Config defines client configuration options.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns default client configuration.
type ConnectionMode ¶
type ConnectionMode = client.ConnectionMode
ConnectionMode specifies the access permission mode of a WebSocket connection.
func ParseConnectionMode ¶
func ParseConnectionMode(s string) (ConnectionMode, error)
ParseConnectionMode parses and validates a string into a ConnectionMode.
type ConnectionState ¶
type ConnectionState = client.ConnectionState
ConnectionState represents the state of the connection.
type Event ¶
Event is the standardized generic message envelope coupling transport metadata with a domain payload.
func NewEventTyped ¶
NewEventTyped constructs a strongly-typed Event[T] with generated ID and metadata.
func RequestPayload ¶
func RequestPayload[Resp any, Req any](ctx context.Context, c ClientInterface, target string, reqType event.EventType, payload Req) (*Event[Resp], error)
RequestPayload creates and sends a typed request, returning a strongly-typed response.
func RequestTyped ¶
func RequestTyped[Resp any](ctx context.Context, c ClientInterface, evt *RawEvent) (*Event[Resp], error)
RequestTyped sends a RawEvent request and unmarshals the correlated response payload into Resp.
type EventHandler ¶
type EventHandler = client.EventHandler
EventHandler is a callback invoked when an event is received.
type FileMessage ¶
type FileMessage = event.FileMessage
FileMessage represents a file attachment payload.
type NTPQueryOptions ¶
type NTPQueryOptions = ntp.QueryOptions
NTPQueryOptions holds options for querying NTP time.
type NTPResponse ¶
NTPResponse is the NTP query response from github.com/beevik/ntp.
type PayloadUnmarshaler ¶
type PayloadUnmarshaler = event.PayloadUnmarshaler
PayloadUnmarshaler defines a factory function that decodes raw JSON payload into a concrete type.
type PublishResponse ¶
type PublishResponse = restclient.PublishResponse
PublishResponse is returned after a REST publish.
type RESTClient ¶
type RESTClient = restclient.RESTClient
RESTClient is the HTTP client for WSBroker REST APIs.
func NewRESTClient ¶
func NewRESTClient(cfg RESTConfig, opts ...RESTOption) (*RESTClient, error)
NewRESTClient creates a new WSBroker REST client.
type RESTConfig ¶
type RESTConfig = restclient.Config
RESTConfig defines configuration for RESTClient.
func DefaultRESTConfig ¶
func DefaultRESTConfig() RESTConfig
DefaultRESTConfig returns default REST client configuration.
type Subscription ¶
type Subscription = client.Subscription
Subscription represents an active channel subscription stream.
type TypedEventHandler ¶
type TypedEventHandler[T any] = client.TypedEventHandler[T]
TypedEventHandler is a callback function invoked with a strongly-typed Event[T].
type TypedSubscription ¶
type TypedSubscription[T any] = client.TypedSubscription[T]
TypedSubscription represents an active streaming channel subscription producing strongly-typed events.
func SubscribeTyped ¶
func SubscribeTyped[T any](ctx context.Context, c ClientInterface, channel string, bufferSize ...int) (TypedSubscription[T], error)
SubscribeTyped returns a streaming TypedSubscription for the given channel, emitting decoded *Event[T].
type UnsubscribeFunc ¶
type UnsubscribeFunc = client.UnsubscribeFunc
UnsubscribeFunc stops a subscription or listener.
func OnChannelTyped ¶
func OnChannelTyped[T any](c ClientInterface, channel string, handler TypedEventHandler[T], errHandler ...func(raw *RawEvent, err error)) UnsubscribeFunc
OnChannelTyped registers a listener for events targeted to a channel with automatic unmarshaling into Event[T].
func OnEventTyped ¶
func OnEventTyped[T any](c ClientInterface, handler TypedEventHandler[T], errHandler ...func(raw *RawEvent, err error)) UnsubscribeFunc
OnEventTyped registers a global event listener with automatic unmarshaling into Event[T].
func OnTyped ¶
func OnTyped[T any](c ClientInterface, eventType EventType, handler TypedEventHandler[T], errHandler ...func(raw *RawEvent, err error)) UnsubscribeFunc
OnTyped registers a listener for events of a specific EventType with automatic unmarshaling into Event[T].
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
wschat
command
|
|
|
demo
|
|
|
pkg
|
|
|
client
Package client provides a robust, mTLS-capable WebSocket client for WSBroker with automatic reconnection, dynamic channel subscription tracking, and event routing.
|
Package client provides a robust, mTLS-capable WebSocket client for WSBroker with automatic reconnection, dynamic channel subscription tracking, and event routing. |
|
event
Package event defines the event envelope data structures, event types, and serialization helpers used by wsbroker clients and servers.
|
Package event defines the event envelope data structures, event types, and serialization helpers used by wsbroker clients and servers. |
|
restclient
Package restclient provides a client for WSBroker's HTTP REST management and publish APIs.
|
Package restclient provides a client for WSBroker's HTTP REST management and publish APIs. |