Documentation
¶
Overview ¶
Package sse implements a Server-Sent Events server.
See https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events.
Index ¶
- func DefaultChannelSizeFunc(ctx context.Context, r *http.Request) int
- func DefaultConnectFunc(ctx context.Context, w http.ResponseWriter, r *http.Request) bool
- func DefaultErrorFunc(ctx context.Context, err error, r *http.Request) error
- func DefaultEstablishedFunc(ctx context.Context, ch chan<- Event, r *http.Request)
- type ChannelSizeFunc
- type ConnectFunc
- type ErrorFunc
- type EstablishedFunc
- type Event
- type Server
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultChannelSizeFunc ¶
DefaultChannelSizeFunc is the default channel size function. It always returns a small non-zero constant.
func DefaultConnectFunc ¶
DefaultConnectFunc is the default connect function. It always returns true.
func DefaultErrorFunc ¶
DefaultErrorFunc is the default error function. It returns err unchanged, i.e. it terminates the connection as soon as any error is encountered.
Types ¶
type ChannelSizeFunc ¶
A ChannelSizeFunc is called when a connection is established. It returns the channel size for the client.
type ConnectFunc ¶
A ConnectFunc is called when a client connects. If it returns true then the connection is established. If it returns false then it should write the response to w.
type ErrorFunc ¶
A ErrorFunc is called when an error is encountered while sending an event. If it returns non-nil then the connection to the client is terminated.
type EstablishedFunc ¶
An EstablishedFunc is called when a connection with the client is established. It receives a channel to which it should write events to be sent to the client. The function must close ch before returning and terminate when r's context is done.
type Event ¶
An Event is a server-sent event.
func (*Event) MarshalText ¶
MarshalText implements encoding.TextMarshaler.MarshalText.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
A Server is a Server-Sent Events Server.
func NewServer ¶
func NewServer(options ...ServerOption) *Server
NewServer returns a new Server with the given options.
type ServerOption ¶
type ServerOption func(*Server)
A ServerOption sets an option on a Server.
func WithChannelSizeFunc ¶
func WithChannelSizeFunc(channelSizeFunc ChannelSizeFunc) ServerOption
WithChannelSizeFunc sets the channel size function.
func WithConnectFunc ¶
func WithConnectFunc(connectFunc ConnectFunc) ServerOption
WithConnectFunc sets the connection function.
func WithErrorFunc ¶
func WithErrorFunc(errorFunc ErrorFunc) ServerOption
WithErrorFunc sets the error function.
func WithEstablishedFunc ¶
func WithEstablishedFunc(establishedFunc EstablishedFunc) ServerOption
WithEstablishedFunc sets the established function.