Documentation ¶
Overview ¶
Package sse implements a server and client for the HTML5 Server-Sent-Events protocol. More protocol information available at https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosedClient = errors.New("client closed")
ErrClosedClient is an error indicating that the client has been used after it was closed.
var ErrFlushNotSupported = errors.New("flush not supported")
ErrFlushNotSupported indicates that the provided http.ResponseWriter does not implement http.Flusher
var ErrNoData = errors.New("event contains no data")
ErrNoData is an error which indicates that an Event has an empty Data field
var ErrNotNCName = errors.New("name is not a valid NCName")
ErrNotNCName is an error indicating that the name of an Event is not a valid NCName See https://www.w3.org/TR/REC-xml-names/#NT-NCName
var ErrNotSSE = errors.New("content type is not 'text/event-stream'")
ErrNotSSE is an error returned when a client receives a non-SSE response
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a SSE client
type ErrIllegalRune ¶
type ErrIllegalRune struct { Name string //Name of field containing rune In string //The string the rune is in Rune rune //The illegal rune }
ErrIllegalRune is an error type which indicates that an illegal rune was in an Event field
func (ErrIllegalRune) Error ¶
func (err ErrIllegalRune) Error() string
type Event ¶
type Event struct { Name string //Name of the event, referred to as "event" (optional) Data string //Event data, referred to as "data" (required) }
Event is an SSE event. See https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events for more info. The "id" and "retry" settings are not currently implemented.
type Handler ¶
Handler is an http.Handler which uses SSE. If there is an error in NewSender, an http.StatusInternalServerError is sent.
type ResponseWriteFlusher ¶
type ResponseWriteFlusher interface { http.ResponseWriter http.Flusher }
ResponseWriteFlusher is an interface combining http.ResponseWriter and http.Flusher. Any http.ResponseWriter used for SSE must also implement http.Flusher.
func Flusher ¶
func Flusher(w http.ResponseWriter) (ResponseWriteFlusher, error)
Flusher tries to get a ResponseWriteFlusher from an http.ResponseWriter
type ScannedEvent ¶
type ScannedEvent struct { Type string // event type Data string // data buffer ID string // last event ID IDSet bool // was the last event ID set Retry int // event stream's reconnection time RetrySet bool // was the Retry delay set }
ScannedEvent is an SSE event. See https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events for more info.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner parses an event stream
func NewScanner ¶
NewScanner returns a Scanner which will parse Event from the io.Reader
func (*Scanner) Event ¶
func (s *Scanner) Event() (ev ScannedEvent, err error)
Event reads an event from the stream.
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender is an HTML5 Server Sent Events sender
func NewSender ¶
func NewSender(w http.ResponseWriter) (*Sender, error)
NewSender creates an SSE event sender using an http.ResponseWriter
func (*Sender) Flush ¶
func (s *Sender) Flush()
Flush flushes the events. This is only necessary after SendQuick.
func (*Sender) SendEvent ¶
SendEvent sends an event. The event is immediately flushed to the client.