longpoll

package module
v0.1.0 Latest Latest
Warning

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

README

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.

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

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

Functions

func MillisecondEpoch

func MillisecondEpoch(now time.Time) int64

func SetLogger

func SetLogger(l logr.Logger)

Types

type Event

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

type Manager

type Manager struct {
	sync.Mutex
	// 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 {
	sync.RWMutex
	// 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