Documentation
¶
Index ¶
- Constants
- Variables
- func IsEmptySource(err error) bool
- type Consumer
- type Error
- type Event
- type List
- type Map
- type Metadata
- type Object
- type Period
- type Producer
- type QueryOptions
- type Service
- type ServiceMiddleware
- func CacheServiceMiddleware(countsCache cache.CountService) ServiceMiddleware
- func InstrumentServiceMiddleware(component, store string, errCount kitmetrics.Counter, ...) ServiceMiddleware
- func LogServiceMiddleware(logger log.Logger, store string) ServiceMiddleware
- func SourcingServiceMiddleware(producer Producer) ServiceMiddleware
- type Source
- type SourceMiddleware
- type StateChange
- type Target
- type Visibility
Constants ¶
const ( TargetUser = "tg_user" TypeFollow = "tg_follow" TypeFriend = "tg_friend" TypeReaction = "tg_reaction" )
TG reserved keywords for types.
Variables ¶
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 ¶
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.
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.
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 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 ¶
PostgresService returns a Postgres based Service implementation.
type ServiceMiddleware ¶
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 SourceMiddleware ¶
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 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.