Documentation ¶
Overview ¶
Package sse implements server-sent events as described by the HTML Standard. See https://html.spec.whatwg.org/multipage/server-sent-events.html for more details.
Currently, only a server implementation is provided.
Index ¶
Constants ¶
const ( // EOL is the end-of-line character for fields and events. EOL byte = '\n' )
Variables ¶
This section is empty.
Functions ¶
func H2CTransport ¶ added in v0.4.0
func H2CTransport() http.RoundTripper
H2CTransport creates a transport that supports HTTP2 cleartext.
Types ¶
type Event ¶ added in v0.4.0
type Event struct { // Comment is a piece of text ignored by the client. // It may be used to send a heartbeat to keep the SSE connection alive. Comment string // Type is the kind of event. // Listeners for this specific type can be dispatched client side to process the event. Type string // Data is the event's content. Data []byte // ID is a unique identifier for the event. ID string // Retry sets the client-side interval for reconnecting to the server. Retry time.Duration // If Raw is true, newlines in the event's data are not escaped. // Escaping prevents accidental truncation of text content. // // However, if it has already been encoded i.e. with JSON, Raw can be set to true. Raw bool }
Event represents a server-sent event. The zero value of an event can be used as-is.
Reference: https://html.spec.whatwg.org/multipage/server-sent-events.html
type Server ¶ added in v0.4.0
type Server struct {
// contains filtered or unexported fields
}
Server is a stream multiplexer, allowing clients to receive events from a specific stream.
func NewServer ¶ added in v0.4.0
NewServer creates a new server.
If defaultStream is not empty, a default stream is created for clients who do not specify a stream to connect to.
func (*Server) Add ¶ added in v0.4.0
Add creates a new stream in the server. If the stream already exists, the existing one is returned.
func (*Server) Get ¶ added in v0.4.0
Get returns an existing stream by name in the server. If the stream does not exist, nil is returned.
func (*Server) Remove ¶ added in v0.4.0
Remove deletes the stream by name from the server and closes it. If the stream does not exist, this is a no-op.