Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WebSocketHandler ¶
func WebSocketHandler(ctx context.Context, options ...Options) http.HandlerFunc
WebSocketHandler creates an HTTP handler via a closure that will upgrade the connection to a websocket and use that websocket as either a publisher or a subscriber.
Types ¶
type Event ¶
type Event struct {
// ClientID is the unique client ID for a client to the subscription that the event is for.
ClientID string `json:"clientID"`
// SubscriptionTopic is the topic of the subscription that generated this event. (The URL path.)
SubscriptionTopic string `json:"subscriptionTopic"`
// Type is an enum that indicates what kind of event has happened.
Type EventType `json:"type"`
}
Event represents an event for a subscription.
type EventType ¶
type EventType uint
EventType is an enum that indicates what kind of event has happened.
const ( // EventTypePublisherLeft is an event that indicates a publisher has left the subscription. EventTypePublisherLeft EventType = 1 // EventTypePublisherJoined is an event that indicates a publisher has joined the subscription. EventTypePublisherJoined EventType = 2 // EventTypeSubscriberLeft is an event that indicates a subscriber has left the subscription. EventTypeSubscriberLeft EventType = 3 // EventTypeSubscriberJoined is an event that indicates a subscriber has joined the subscription. EventTypeSubscriberJoined EventType = 4 // EventTypeWebsocketUpgradeFailed is an event that indicates a websocket upgrade failed. EventTypeWebsocketUpgradeFailed EventType = 5 // EventTypeBadHTTPHeaders is an event that indicates a incoming request didn't have appropriate HTTP headers. EventTypeBadHTTPHeaders EventType = 6 )
type Options ¶
type Options struct {
// Options are the options for all subscriptions created by the service.
Options *SubscriptionOptions
// Upgrader is the websocket upgrader to when clients connect.
Upgrader *websocket.Upgrader
}
Options represents all of the websocket pubsub information that already has default values.
type SubscriptionOptions ¶
type SubscriptionOptions struct {
// CloseDeadline is the time to wait to gracefully closing something. After that, it's closed regardless.
CloseDeadline *time.Duration
// Events is a channel of events for the subscription.
Events chan<- Event
// MessageBuffer is the internal channel buffer for messages for the subscription.
MessageBuffer uint
// PongDeadline is the time to wait for a pong message after a ping.
PongDeadline *time.Duration
// PublisherBuffer is the internal channel buffer for adding and removing publishers.
PublisherBuffer uint
// SubscriberBuffer is the internal channel buffer for adding and remove subscribers.
SubscriberBuffer uint
// SubscriberWriteTimeout is the time to wait for a message to be written to a subscriber. If the message is not
// written in this amount of time, the subscriber is closed.
SubscriberWriteTimeout *time.Duration
}
SubscriptionOptions represents information used to create a subscription that already has default values.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
generate_test_data
command
|
|
|
server
command
|
|
|
examples
|
|
|
cli/publisher
command
|
|
|
cli/subscriber
command
|
|
|
simple/publisher
command
|
|
|
simple/subscriber
command
|
|
Click to show internal directories.
Click to hide internal directories.