events

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 11 Imported by: 2

README

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyPayload     = errors.New("empty payload")
	ErrIteratorNotFound = errors.New("iterator not found")
	ErrInvalidType      = errors.New("invalid type")
)
View Source
var (
	ErrTimeout = errors.New("timeout")
)

Functions

func CloseIterator

func CloseIterator(svc Service) endpoint.Endpoint

func FetchFromIterator

func FetchFromIterator(svc Service) endpoint.Endpoint

func IteratorEndpoint

func IteratorEndpoint(svc Service) endpoint.Endpoint

func MinifyMiddleware

func MinifyMiddleware() endpoint.Middleware

func NewIteratorEndpoint added in v1.0.1

func NewIteratorEndpoint(svc Service) endpoint.Endpoint

func StoreEndpoint

func StoreEndpoint(svc Service) endpoint.Endpoint

Types

type Config

type Config struct {
	Persistence Persistence `yaml:"persistence"`
	Path        string      `yaml:"-"`
}

func (*Config) SetPath

func (cfg *Config) SetPath(path string)

type DataType added in v1.0.2

type DataType int
const (
	Any DataType = iota
	JSON
	Bytes
)

type Event

type Event struct {
	ID      ulid.ULID `json:"id"`
	Topic   string    `json:"topic"`
	Payload Payload   `json:"payload"`
}

func NewEvent

func NewEvent(topic string, payload Payload, ids ...ulid.ULID) *Event

func (*Event) Time

func (e *Event) Time() time.Time

type FetchFromIteratorRequest

type FetchFromIteratorRequest struct {
	ID    string
	Batch int
}

type Iterator

type Iterator interface {
	ID() string
	Fetch(batch int) ([]*Event, error)
	Close(err error)
	Done() <-chan struct{}
	Err() error
}

type NewIteratorRequest added in v1.0.1

type NewIteratorRequest struct {
	Topic string    `json:"topic"`
	Since time.Time `json:"since"`
}

type Payload added in v1.0.2

type Payload struct {
	Data any
	Type DataType
}

func NewPayload added in v1.0.2

func NewPayload(data any) Payload

func NewPayloadFromBytes added in v1.0.2

func NewPayloadFromBytes(data []byte, raw ...bool) (p Payload, err error)

func NewPayloadFromJSON added in v1.0.2

func NewPayloadFromJSON(data json.RawMessage) Payload

func (*Payload) Bytes added in v1.0.2

func (p *Payload) Bytes() ([]byte, bool)

func (*Payload) JSON added in v1.0.2

func (p *Payload) JSON() (json.RawMessage, bool)

func (*Payload) MarshalJSON added in v1.0.2

func (p *Payload) MarshalJSON() ([]byte, error)

func (*Payload) SetBytes added in v1.0.2

func (p *Payload) SetBytes(data []byte)

func (*Payload) SetData added in v1.0.2

func (p *Payload) SetData(data any)

func (*Payload) SetJSON added in v1.0.2

func (p *Payload) SetJSON(data json.RawMessage)

func (*Payload) UnmarshalJSON added in v1.0.2

func (p *Payload) UnmarshalJSON(data []byte) error

type Persistence

type Persistence struct {
	Driver StorageDriver `yaml:"driver"`
	DSN    string        `yaml:"dsn"`
}

type Repository

type Repository interface {
	Store(e *Event) error
	Iterator(ctx context.Context, since time.Time) (Iterator, error)
	Close() error
}

type Service

type Service interface {
	Up()
	Down()
	Store(topic string, payload Payload, ids ...ulid.ULID) error
	NewIterator(topic string, since time.Time) (string, error)
	Iterator(id string) (Iterator, error)

	// Iterator
	FetchFromIterator(batch int, id string) ([]*Event, error)
	CloseIterator(id string) error
}

func NewService

func NewService(events Repository) Service

type ServiceMiddleware

type ServiceMiddleware func(Service) Service

func LoggingMiddleware

func LoggingMiddleware(log *zap.Logger) ServiceMiddleware

type StorageDriver

type StorageDriver string
const (
	InMem StorageDriver = "inmem"

	BadgerDB StorageDriver = "badger"
	Redis    StorageDriver = "redis"

	InfluxDB   StorageDriver = "influxdb"
	InfluxDBv2 StorageDriver = "influxdb2"

	MySQL      StorageDriver = "mysql"
	SQLServer  StorageDriver = "sqlserver"
	PostgreSQL StorageDriver = "postgres"
	SQLite     StorageDriver = "sqlite"

	// Document Database
	MongoDB StorageDriver = "mongo"
)

type StoreRequest

type StoreRequest struct {
	ID      ulid.ULID `json:"id"`
	Topic   string    `json:"topic"`
	Payload Payload   `json:"payload"`
}

Directories

Path Synopsis
transport

Jump to

Keyboard shortcuts

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