sse

package module
v0.0.0-...-72db694 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 5 Imported by: 7

README

SSE - Server-Sent Events

Build Status Coverage GoDoc

HTML5 Server-Sent Events for Go

Why you should use Server-Sent-Events

  • No need to implement custom protocol (WebSockets), it just uses HTTP
  • Convenient JavaScript API, fires easy to handle Events
  • Auto-Reconnects
  • Unlike WebSockets, only unidirectional (server -> client)

ToDo

  • ID handling
  • Improve Client Channel buffering

Further Readings

Documentation

Overview

Package sse provides HTML5 Server-Sent Events for Go.

See http://www.w3.org/TR/eventsource/ for the technical specification

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Streamer

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

Streamer receives events and broadcasts them to all connected clients. Streamer is a http.Handler. Clients making a request to this handler receive a stream of Server-Sent Events, which can be handled via JavaScript. See the linked technical specification for details.

func New

func New() *Streamer

New returns a new initialized SSE Streamer

func (*Streamer) BufSize

func (s *Streamer) BufSize(size uint)

BufSize sets the event buffer size for new clients.

func (*Streamer) SendBytes

func (s *Streamer) SendBytes(id, event string, data []byte)

SendBytes sends an event with the given byte slice interpreted as a string as the data value to all connected clients. If the id or event string is empty, no id / event type is send.

func (*Streamer) SendInt

func (s *Streamer) SendInt(id, event string, data int64)

SendInt sends an event with the given int as the data value to all connected clients. If the id or event string is empty, no id / event type is send.

func (*Streamer) SendJSON

func (s *Streamer) SendJSON(id, event string, v interface{}) error

SendJSON sends an event with the given data encoded as JSON to all connected clients. If the id or event string is empty, no id / event type is send.

func (*Streamer) SendString

func (s *Streamer) SendString(id, event, data string)

SendString sends an event with the given data string to all connected clients. If the id or event string is empty, no id / event type is send.

func (*Streamer) SendUint

func (s *Streamer) SendUint(id, event string, data uint64)

SendUint sends an event with the given unsigned int as the data value to all connected clients. If the id or event string is empty, no id / event type is send.

func (*Streamer) ServeHTTP

func (s *Streamer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface.

Jump to

Keyboard shortcuts

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