package module
v0.1.0 Latest Latest

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

Go to latest
Published: May 15, 2020 License: MIT Imports: 12 Imported by: 0


Golang HTTP Longpoll Server

This library is heavily inspired by J Cuga's golongpoll project. I just needed to simplify some things.

Main Changes

  • No more categories - each category needs to have its own longpoll instance.
  • Last Value Cache - when creating a new longpoll manager, you can specify if it should just cache the last published value rather than maintain a history of published values.



Implementation of a HTTP Longpoll client and server.

This package is heavily inspired by J Cuga's `golongpoll` package (https://github.com/jcuga/golongpoll). It provides a longpoll client and server and supports both last-value cache (LVC) or a full event history.



This section is empty.


View Source
var ErrNoSubscribers = errors.New("no subscribers")


func MillisecondEpoch

func MillisecondEpoch(now time.Time) int64

func SetLogger

func SetLogger(l logr.Logger)


type Event

type Event struct {
	Data json.RawMessage `json:"data"`

type Manager

type Manager struct {
	// contains filtered or unexported fields

func NewManager

func NewManager(opts ...ManagerOption) *Manager

func (*Manager) Publish

func (this *Manager) Publish(data interface{}) error

func (*Manager) ServeHTTP

func (this *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Manager) Start

func (this *Manager) Start(ctx context.Context) error

type ManagerOption

type ManagerOption func(*managerOptions)

func LVC

func LVC(l bool) ManagerOption

func MaxTimeout

func MaxTimeout(m int) ManagerOption

type Message

type Message struct {
	Error     string  `json:"error"`
	Timestamp int64   `json:"timestamp"`
	Events    []Event `json:"events"`

type Watcher

type Watcher struct {
	// contains filtered or unexported fields

func NewWatcher

func NewWatcher(opts ...WatcherOption) *Watcher

func (*Watcher) Watch

func (this *Watcher) Watch(ctx context.Context, path string, events chan Event) error

type WatcherOption

type WatcherOption func(*watcherOptions)

func Endpoint

func Endpoint(e string) WatcherOption

func Since

func Since(s time.Time) WatcherOption

func Transport

func Transport(t *http.Transport) WatcherOption

Jump to

Keyboard shortcuts

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