Documentation ¶
Overview ¶
Package sse implements Server Sent Event API for szmaterlok backend server. You'll find here both type models and http methods and functions.
Index ¶
Constants ¶
View Source
const ContentTypeEventStream string = "text/event-stream"
ContentTypeEventStream is content type for event stream filetype.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct { // Type is a string identifying the type of event described. If // this is specified, an event will be dispatched on the browser // to the listener for the specified event name; the website source // code should use addEventListener() to listen for named events. Type string // Data is the field for the message. Data []byte // ID is unique event identifier. ID string // Retry is reconnection time. If the connection to the server is lost, the // browser will wait for the specified time before attempting to reconnect. // This must be an integer, specifying the reconnection time in milliseconds. // If a non-integer value is specified, the field is ignored. Retry int64 }
Event is a simple stream of text data which must be encoded using UTF-8. Messages in the event stream are separated by a pair of newline characters. A colon as the first character of a line is in essence a comment, and is ignored.
Sample event stream.
event: usermessage data: {"username": "bobby", "time": "02:34:11", "text": "Hi everyone."}
Below and above documentation is mostly copied from MDN. Source: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
Click to show internal directories.
Click to hide internal directories.