Documentation
¶
Index ¶
- type Actor
- type ActorOption
- func WithHTTPClient(c *http.Client) ActorOption
- func WithMailboxSize(size int) ActorOption
- func WithOnConnect(handler func(url string)) ActorOption
- func WithOnError(handler func(err error)) ActorOption
- func WithOnMessage(handler func(msg Message, duration time.Duration)) ActorOption
- func WithPingInterval(d time.Duration) ActorOption
- type Message
- type MessageType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Actor ¶
Actor connects to a WebSocket endpoint, delivers inbound messages to a handler, and exposes a thread-safe Send method for outbound messages. It is designed to run under a sup.Supervisor, which handles reconnection on failure.
func NewActor ¶
func NewActor(name string, url string, handler func(Message), opts ...ActorOption) *Actor
NewActor creates a new Actor with the specified URL, inbound message handler, and optional configuration options.
type ActorOption ¶
type ActorOption func(*Actor)
ActorOption defines a function type for configuring the Actor.
func WithHTTPClient ¶
func WithHTTPClient(c *http.Client) ActorOption
WithHTTPClient allows providing a custom http.Client for the WebSocket dial.
func WithMailboxSize ¶
func WithMailboxSize(size int) ActorOption
WithMailboxSize sets the size of the actor's outbound mailbox. Default is 10.
func WithOnConnect ¶ added in v0.0.3
func WithOnConnect(handler func(url string)) ActorOption
WithOnConnect sets a callback that is invoked with the URL whenever a connection is successfully established.
func WithOnError ¶ added in v0.0.3
func WithOnError(handler func(err error)) ActorOption
WithOnError sets a callback that is invoked with any error that causes the actor to fail and trigger a supervisor restart.
func WithOnMessage ¶ added in v0.0.3
func WithOnMessage(handler func(msg Message, duration time.Duration)) ActorOption
WithOnMessage sets a callback that is invoked with each received message and the duration since the last message was processed.
func WithPingInterval ¶
func WithPingInterval(d time.Duration) ActorOption
WithPingInterval sets how often the actor sends pings to keep the connection alive and detect silent drops. Default is 15 seconds.
type Message ¶
type Message struct {
Type MessageType
Data []byte
}
Message represents a single WebSocket message with its type and payload.
type MessageType ¶
type MessageType int
MessageType represents the type of a WebSocket message frame.
const ( MessageText MessageType = MessageType(websocket.MessageText) MessageBinary MessageType = MessageType(websocket.MessageBinary) )