Documentation
¶
Overview ¶
Package sse implements Server-Sent Events that supports multiple channels.
Server-sent events is a method of continuously sending data from a server to the browser, rather than repeatedly requesting it.
Examples ¶
Basic usage of sse package.
s := sse.NewServer(nil)
defer s.Shutdown()
http.Handle("/events/", s)
Index ¶
- type Channel
- type Client
- type Message
- type Options
- type Server
- func (s *Server) Channels() []string
- func (s *Server) ClientCount() int
- func (s *Server) CloseChannel(name string)
- func (s *Server) GetChannel(name string) (*Channel, bool)
- func (s *Server) HasChannel(name string) bool
- func (s *Server) Restart()
- func (s *Server) SendMessage(channel string, message *Message)
- func (s *Server) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (s *Server) Shutdown()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
func NewChannel ¶
func (*Channel) ClientCount ¶
func (*Channel) LastEventId ¶
func (*Channel) SendMessage ¶
SendMessage broadcast a message to all clients in a channel.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) LastEventId ¶
func (*Client) SendMessage ¶
SendMessage sends a message to client.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
func NewMessage ¶
func SimpleMessage ¶
type Options ¶
type Options struct {
// RetryInterval change EventSource default retry interval (milliseconds).
RetryInterval int
// Headers allow to set custom headers (useful for CORS support).
Headers map[string]string
// ChannelNameFunc allow to create custom channel names.
// Default channel name is the request path.
ChannelNameFunc func(*http.Request) string
// All usage logs end up in Logger
Logger *log.Logger
}
func (*Options) HasHeaders ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) ClientCount ¶
func (*Server) CloseChannel ¶
func (*Server) HasChannel ¶
func (*Server) Restart ¶
func (s *Server) Restart()
Restart closes all channels and clients and allow new connections.
func (*Server) SendMessage ¶
SendMessage broadcast a message to all clients in a channel. If channel is an empty string, it will broadcast the message to all channels.
Click to show internal directories.
Click to hide internal directories.