event

package
v0.0.0-...-4347b6b Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TargetUser   = "tg_user"
	TypeFollow   = "tg_follow"
	TypeFriend   = "tg_friend"
	TypeReaction = "tg_reaction"
)

TG reserved keywords for types.

Variables

View Source
var (
	ErrEmptySource       = errors.New("empty source")
	ErrInvalidEvent      = errors.New("invalid event")
	ErrNamespaceNotFound = errors.New("namespace not found")
	ErrNotFound          = errors.New("event not found")
)

Common errors for Event implementations.

Functions

func IsEmptySource

func IsEmptySource(err error) bool

IsEmptySource indicates if err is ErrEmptySource.

Types

type Consumer

type Consumer interface {
	Consume() (*StateChange, error)
}

Consumer observes state changes.

type Error

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

Error wraps common Event errors.

func (Error) Error

func (e Error) Error() string

type Event

type Event struct {
	Enabled    bool       `json:"enabled"`
	ID         uint64     `json:"id"`
	Language   string     `json:"language,omitempty"`
	Metadata   Metadata   `json:"metadata,omitempty"`
	Object     *Object    `json:"object,omitempty"`
	ObjectID   uint64     `json:"object_id"`
	Owned      bool       `json:"owned"`
	Target     *Target    `json:"target"`
	Type       string     `json:"type"`
	UserID     uint64     `json:"user_id"`
	Visibility Visibility `json:"visibility"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

Event is the buidling block to express interaction on internal/external objects.

func (*Event) MatchOpts

func (e *Event) MatchOpts(opts *QueryOptions) bool

MatchOpts indicates if the Event matches the given QueryOptions.

func (Event) Validate

func (e Event) Validate() error

Validate performs semantic checks on the passed Event values for correctness.

type List

type List []*Event

List is an Event collection.

func (List) IDs

func (es List) IDs() []uint64

IDs returns ID for every Event.

func (List) Len

func (es List) Len() int

func (List) Less

func (es List) Less(i, j int) bool

func (List) Swap

func (es List) Swap(i, j int)

func (List) UserIDs

func (es List) UserIDs() []uint64

UserIDs returns UserID for every Event.

type Map

type Map map[uint64]*Event

Map is an event collection with the id as index.

type Metadata

type Metadata map[string]string

Metadata is a bucket of additional event information.

type Object

type Object struct {
	DisplayNames map[string]string `json:"display_names,omitempty"`
	ID           string            `json:"id"`
	Type         string            `json:"type"`
	URL          string            `json:"url"`
}

Object describes an external entity whcih can have a type and an id.

type Period

type Period string

Period is a pre-defined time duration.

const (
	ByDay   Period = "1 day"
	ByWeek  Period = "1 week"
	ByMonth Period = "1 month"
)

Predefined time periods to use for aggregates.

type Producer

type Producer interface {
	Propagate(namespace string, old, new *Event) (string, error)
}

Producer creates a state change notification.

type QueryOptions

type QueryOptions struct {
	After               time.Time    `json:"-"`
	Before              time.Time    `json:"-"`
	Enabled             *bool        `json:"enabled"`
	ExternalObjectIDs   []string     `json:"-"`
	ExternalObjectTypes []string     `json:"-"`
	IDs                 []uint64     `json:"ids"`
	Limit               int          `json:"-"`
	ObjectIDs           []uint64     `json:"object_ids"`
	Owned               *bool        `json:"owned"`
	TargetIDs           []string     `json:"-"`
	TargetTypes         []string     `json:"-"`
	Types               []string     `json:"types"`
	UserIDs             []uint64     `json:"user_ids"`
	Visibilities        []Visibility `json:"visibilities"`
}

QueryOptions are used to narrow down Event queries.

type Service

type Service interface {
	service.Lifecycle

	Count(namespace string, opts QueryOptions) (int, error)
	Put(namespace string, event *Event) (*Event, error)
	Query(namespace string, opts QueryOptions) (List, error)
}

Service for event interactions.

func MemService

func MemService() Service

MemService returns a memory backed implementation of Service.

func PostgresService

func PostgresService(db *sqlx.DB) Service

PostgresService returns a Postgres based Service implementation.

type ServiceMiddleware

type ServiceMiddleware func(Service) Service

ServiceMiddleware is a chainable behaviour modifier for Service.

func CacheServiceMiddleware

func CacheServiceMiddleware(countsCache cache.CountService) ServiceMiddleware

CacheServiceMiddleware adds caching capabilities to the Service by using read-through and write-through methods to store results of heavy computation with sensible TTLs.

func InstrumentServiceMiddleware

func InstrumentServiceMiddleware(
	component, store string,
	errCount kitmetrics.Counter,
	opCount kitmetrics.Counter,
	opLatency *prometheus.HistogramVec,
) ServiceMiddleware

InstrumentMiddleware observes key apsects of Service operations and exposes Prometheus metrics.

func LogServiceMiddleware

func LogServiceMiddleware(logger log.Logger, store string) ServiceMiddleware

LogServiceMiddleware given a Logger wraps the next Service with logging capabilities.

func SourcingServiceMiddleware

func SourcingServiceMiddleware(producer Producer) ServiceMiddleware

SourcingServiceMiddleware propagates state changes for the Service via the given Producer.

type Source

type Source interface {
	source.Acker
	Consumer
	Producer
}

Source encapsulates state change notifications operations.

func NopSource

func NopSource() Source

NopSource returns a noop implementation of Source.

func SQSSource

func SQSSource(api platformSQS.API) (Source, error)

SQSSource returns an SQS backed Source implementation.

type SourceMiddleware

type SourceMiddleware func(Source) Source

SourceMiddleware is a chainable behaviour modifier for Source.

func InstrumentSourceMiddleware

func InstrumentSourceMiddleware(
	component, store string,
	errCount kitmetrics.Counter,
	opCount kitmetrics.Counter,
	opLatency *prometheus.HistogramVec,
	queueLatency *prometheus.HistogramVec,
) SourceMiddleware

InstrumentSourceMiddleware observes key aspects of Source operations and exposes Prometheus metrics.

func LogSourceMiddleware

func LogSourceMiddleware(store string, logger log.Logger) SourceMiddleware

LogSourceMiddleware given a Logger wraps the next Source logging capabilities.

type StateChange

type StateChange struct {
	AckID     string
	ID        string
	Namespace string
	New       *Event
	Old       *Event
	SentAt    time.Time
}

StateChange transports all information necessary to observe state changes.

type Target

type Target struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

Target describes the person addressed in an event. To be phased out.

type Visibility

type Visibility uint8

Visibility determines the visibility of Objects when consumed.

const (
	VisibilityPrivate Visibility = (iota + 1) * 10
	VisibilityConnection
	VisibilityPublic
	VisibilityGlobal
)

Visibility variants available for Events.

Jump to

Keyboard shortcuts

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