sse

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSSENotSupported indicates the HTTP handler does not support server-sent events.
	ErrSSENotSupported = errors.New("response writer does not support SSE")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a HTTP/2 client that can receive server-sent events.

func NewClient

func NewClient(w http.ResponseWriter, r *http.Request) (Client, error)

NewClient creates a new client. If the client does not support SSE, ErrSSENotSupported is returned as the error.

func (Client) Send

func (c Client) Send(msg Message) (int64, error)

Send sends the message to the client, returning the number of message bytes written and the error encountered, if any.

type Message

type Message struct {
	// The event type. If empty, the event field is omitted.
	Event string

	// The data to send.
	Data []byte
}

Message represents a server-sent event.

func (Message) Marshal

func (m Message) Marshal(buf *bytes.Buffer)

Marshal serializes the message into a buffer. Note that the buffer is reset beforehand.

type Stream

type Stream struct {
	Errors chan error
	// contains filtered or unexported fields
}

Stream represents a group of clients that messages can be broadcasted to.

func NewStream

func NewStream() *Stream

Stream creates a new stream.

func (*Stream) Add

func (s *Stream) Add(c Client)

Add adds a client to the stream.

func (*Stream) Close

func (s *Stream) Close()

Close closes the stream, dropping all messages.

func (*Stream) Send

func (s *Stream) Send(m Message)

Send broadcasts a message to all clients in the stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL