Documentation ¶
Overview ¶
Package sse provides a utility for upgrading http requests to event streaming connections with server sent events (SSE).
Index ¶
- type Connection
- func (connection *Connection) BuildMessage() *MessageBuilder
- func (connection *Connection) Close()
- func (connection *Connection) IsOpen() bool
- func (connection *Connection) SendBytes(data []byte) error
- func (connection *Connection) SendJson(data interface{}) error
- func (connection *Connection) SendString(data string) error
- type Message
- type MessageBuilder
- func (messageBuilder *MessageBuilder) SendBytes(data []byte) error
- func (messageBuilder *MessageBuilder) SendJson(data interface{}) error
- func (messageBuilder *MessageBuilder) SendString(data string) error
- func (messageBuilder *MessageBuilder) WithEvent(event string) *MessageBuilder
- func (messageBuilder *MessageBuilder) WithId(id string) *MessageBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection provides channels for sending event messages, closing the connection and receiving errors from writing to the http response
func Upgrade ¶
func Upgrade(writer http.ResponseWriter, request *http.Request) (*Connection, error)
Upgrade sends headers to client to upgrade the request to an SSE connection and returns a Connection handle for sending messages.
func (*Connection) BuildMessage ¶
func (connection *Connection) BuildMessage() *MessageBuilder
BuildMessage returns a MessageBuilder, a fluent-style builder api for sending events
func (*Connection) Close ¶
func (connection *Connection) Close()
Close sends a shutdown signal to close the connection for streaming data
func (*Connection) IsOpen ¶
func (connection *Connection) IsOpen() bool
IsOpen returns whether connection is still open for sending event data
func (*Connection) SendBytes ¶
func (connection *Connection) SendBytes(data []byte) error
SendBytes sends a series of bytes for an event's data without an id or event field
func (*Connection) SendJson ¶
func (connection *Connection) SendJson(data interface{}) error
SendJson marshals data into a json string for an event's data and sends it without an id or event field
func (*Connection) SendString ¶
func (connection *Connection) SendString(data string) error
SendString sends a string for an event's data without an id or event field
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message contains id, event and data attributes of an event message
type MessageBuilder ¶
type MessageBuilder struct {
// contains filtered or unexported fields
}
MessageBuilder is a fluent-style builder api for sending events
func (*MessageBuilder) SendBytes ¶
func (messageBuilder *MessageBuilder) SendBytes(data []byte) error
SendBytes sends a series of bytes with the specified id and event attributes
func (*MessageBuilder) SendJson ¶
func (messageBuilder *MessageBuilder) SendJson(data interface{}) error
SendJson marshals data into a json string and sends it without an id or event field
func (*MessageBuilder) SendString ¶
func (messageBuilder *MessageBuilder) SendString(data string) error
SendBytes sends a string with the specified id and event attributes
func (*MessageBuilder) WithEvent ¶
func (messageBuilder *MessageBuilder) WithEvent(event string) *MessageBuilder
WithEvent adds an event attribute to event data
func (*MessageBuilder) WithId ¶
func (messageBuilder *MessageBuilder) WithId(id string) *MessageBuilder
WithId adds an id attribute to event data