autoupdate

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package autoupdate allows clients to request keys and get updates when the keys changes.

To register to the autoupdate serive, a client has to receive a connection object by calling the Connect()-method. It is not necessary and therefore not possible to close a connection. The client can just stop listening.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Autoupdate

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

Autoupdate holds the state of the autoupdate service. It has to be initialized with autoupdate.New().

func New

func New(datastore Datastore, restricter RestrictMiddleware, voteAddr string, closed <-chan struct{}) *Autoupdate

New creates a new autoupdate service.

The attribute closed is a channel that should be closed when the server shuts down. In this case, all connections get closed.

func (*Autoupdate) Connect

func (a *Autoupdate) Connect(userID int, kb KeysBuilder) DataProvider

Connect has to be called by a client to register to the service. The method returns a Connection object, that can be used to receive the data.

There is no need to "close" the Connection object.

func (*Autoupdate) LastID

func (a *Autoupdate) LastID() uint64

LastID returns the id of the last data update.

func (*Autoupdate) PruneOldData

func (a *Autoupdate) PruneOldData(ctx context.Context)

PruneOldData removes old data from the topic. Blocks until the service is closed.

func (*Autoupdate) ResetCache

func (a *Autoupdate) ResetCache(ctx context.Context)

ResetCache runs in the background and cleans the cache from time to time. Blocks until the service is closed.

type DataProvider

type DataProvider func(ctx context.Context) (map[string][]byte, error)

DataProvider is a function that returns the next data for a user.

type Datastore

type Datastore interface {
	Get(ctx context.Context, keys ...string) (map[string][]byte, error)
	RegisterChangeListener(f func(map[string][]byte) error)
	ResetCache()
	RegisterCalculatedField(field string, f func(ctx context.Context, key string, changed map[string][]byte) ([]byte, error))
	RequestKeys(url string, keys []string) (map[string][]byte, error)
}

Datastore gets values for keys and informs, if they change.

type KeysBuilder

type KeysBuilder interface {
	Update(ctx context.Context, ds datastore.Getter) error
	Keys() []string
}

KeysBuilder holds the keys that are requested by a user.

type RestrictMiddleware

type RestrictMiddleware func(getter datastore.Getter, uid int) datastore.Getter

RestrictMiddleware is a function that can restrict data.

Jump to

Keyboard shortcuts

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