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

package sse

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

Package sse implements a fully concurrent Server-Sent Events library.

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)

http.Handle("/events/", s)

Index

Package Files

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

type Message Uses

type Message struct {
    Id,
    Data,
    Event string
    Retry int
}

Message describes what the server can send

func (*Message) ToBuffer Uses

func (m *Message) ToBuffer() (buffer *bytes.Buffer)

ToBuffer exports the message to a bytes buffer

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
    // All usage logs end up in Logger
    Logger *log.Logger
    // Called when a new client appears. Return a set of messages to send before current messages
    InitMessages func(ClientLastEventId string, ServerLastEventId string) []Message
}

Options contains configuration for the server

type Server Uses

type Server struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

Server holds the info for a server

func NewServer Uses

func NewServer(options *Options) *Server

NewServer creates a new SSE server.

func (*Server) GetClientsCount Uses

func (s *Server) GetClientsCount() int

GetClientsCount outputs the current number of active http connections

func (*Server) LastEventId Uses

func (s *Server) LastEventId() string

LastEventId returns the event id of the last event to have been sent

func (*Server) Restart Uses

func (s *Server) Restart()

Restart closes all clients and allow new connections.

func (*Server) SendMessage Uses

func (s *Server) SendMessage(message Message)

SendMessage broadcast a message to all clients

func (*Server) ServeHTTP Uses

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

ServeHTTP is the basic handler for go's http package

Directories

PathSynopsis
examples

Package sse imports 5 packages (graph) and is imported by 1 packages. Updated 2019-12-15. Refresh now. Tools for package owners.