go-sse: github.com/AdminXVII/go-sse Index | Files | Directories

package sse

import "github.com/AdminXVII/go-sse"

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

Package Files

channel.go client.go doc.go message.go options.go sse.go

type Channel Uses

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

func NewChannel Uses

func NewChannel(name string) *Channel

func (*Channel) ClientCount Uses

func (c *Channel) ClientCount() int

func (*Channel) Close Uses

func (c *Channel) Close()

func (*Channel) LastEventId Uses

func (c *Channel) LastEventId() string

func (*Channel) SendMessage Uses

func (c *Channel) SendMessage(message *Message)

SendMessage broadcast a message to all clients in a channel.

type Client Uses

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

func NewClient Uses

func NewClient(lastEventId, channel string) *Client

func (*Client) Channel Uses

func (c *Client) Channel() string

Channel returns the channel where this client is subscribe to.

func (*Client) LastEventId Uses

func (c *Client) LastEventId() string

func (*Client) SendMessage Uses

func (c *Client) SendMessage(message *Message)

SendMessage sends a message to client.

type Message Uses

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

func NewMessage Uses

func NewMessage(id, data, event string) *Message

func SimpleMessage Uses

func SimpleMessage(data string) *Message

func (*Message) String Uses

func (m *Message) String() string

type Options Uses

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 Uses

func (opt *Options) HasHeaders() bool

type Server Uses

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

func NewServer Uses

func NewServer(options *Options) *Server

NewServer creates a new SSE server.

func (*Server) Channels Uses

func (s *Server) Channels() []string

func (*Server) ClientCount Uses

func (s *Server) ClientCount() int

func (*Server) CloseChannel Uses

func (s *Server) CloseChannel(name string)

func (*Server) GetChannel Uses

func (s *Server) GetChannel(name string) (*Channel, bool)

func (*Server) HasChannel Uses

func (s *Server) HasChannel(name string) bool

func (*Server) Restart Uses

func (s *Server) Restart()

Restart closes all channels and clients and allow new connections.

func (*Server) SendMessage Uses

func (s *Server) SendMessage(channel string, message *Message)

SendMessage broadcast a message to all clients in a channel. If channel is an empty string, it will broadcast the message to all channels.

func (*Server) ServeHTTP Uses

func (s *Server) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*Server) Shutdown Uses

func (s *Server) Shutdown()

Shutdown performs a graceful server shutdown.

Directories

PathSynopsis
examples

Package sse imports 6 packages (graph) and is imported by 1 packages. Updated 2018-08-05. Refresh now. Tools for package owners.