period

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateFunc

type AggregateFunc[T any, AggregateT json.Marshaler] func(entries []*T, query url.Values) (total int, result AggregateT)

type Entries

type Entries[T any] struct {
	// contains filtered or unexported fields
}

func (*Entries[T]) Add

func (e *Entries[T]) Add(now time.Time, info *T)

func (*Entries[T]) Get

func (e *Entries[T]) Get() []*T

func (*Entries[T]) MarshalJSON

func (e *Entries[T]) MarshalJSON() ([]byte, error)

func (*Entries[T]) UnmarshalJSON

func (e *Entries[T]) UnmarshalJSON(data []byte) error

type Filter

type Filter string

type FilterFunc

type FilterFunc[T any] func(entries []*T, keyword string) (filtered []*T)

type Period

type Period[T any] struct {
	Entries map[Filter]*Entries[T] `json:"entries"`
	// contains filtered or unexported fields
}

func NewPeriod

func NewPeriod[T any]() *Period[T]

func (*Period[T]) Add

func (p *Period[T]) Add(info *T)

func (*Period[T]) Get

func (p *Period[T]) Get(filter Filter) ([]*T, bool)

func (*Period[T]) Total

func (p *Period[T]) Total() int

type PollFunc

type PollFunc[T any] func(ctx context.Context, lastResult *T) (*T, error)

type Poller

type Poller[T any, AggregateT json.Marshaler] struct {
	// contains filtered or unexported fields
}

func NewPoller

func NewPoller[T any, AggregateT json.Marshaler](
	name string,
	poll PollFunc[T],
	aggregator AggregateFunc[T, AggregateT],
) *Poller[T, AggregateT]

func (*Poller[T, AggregateT]) Get

func (p *Poller[T, AggregateT]) Get(filter Filter) ([]*T, bool)

func (*Poller[T, AggregateT]) GetLastResult

func (p *Poller[T, AggregateT]) GetLastResult() *T

func (*Poller[T, AggregateT]) ServeHTTP

func (p *Poller[T, AggregateT]) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the data for the given period.

If the period is not specified, it serves the last result.

If the period is specified, it serves the data for the given period.

If the period is invalid, it returns a 400 error.

If the data is not found, it returns a 204 error.

If the request is a websocket request, it serves the data for the given period for every interval.

func (*Poller[T, AggregateT]) Start

func (p *Poller[T, AggregateT]) Start()

func (*Poller[T, AggregateT]) WithResultFilter

func (p *Poller[T, AggregateT]) WithResultFilter(filter FilterFunc[T]) *Poller[T, AggregateT]

Jump to

Keyboard shortcuts

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