reaction

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: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TypeToIdentifier = map[Type]string{
	TypeLike:  "like",
	TypeLove:  "love",
	TypeHaha:  "haha",
	TypeWow:   "wow",
	TypeSad:   "sad",
	TypeAngry: "angry",
}

TypeToIdentifier is the lookup of a reaction type to human readable idenitfier.

Functions

This section is empty.

Types

type Consumer

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

Consumer observes state changes.

type Counts

type Counts struct {
	Angry uint64
	Haha  uint64
	Like  uint64
	Love  uint64
	Sad   uint64
	Wow   uint64
}

Counts bundles all Reaction counts by type.

type CountsMap

type CountsMap map[uint64]Counts

CountsMap is the association of an object id to Counts.

type List

type List []*Reaction

List is a collection of Reaction.

func (List) Len

func (rs List) Len() int

func (List) Less

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

func (List) OwnerIDs

func (rs List) OwnerIDs() []uint64

OwnerIDs returns the list of owner ids for the Reaction collection.

func (List) Swap

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

type Map

type Map map[uint64]*Reaction

Map is a Reaction collection with their id as index.

func (Map) ToList

func (m Map) ToList() List

ToList returns a list collection.

type Producer

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

Producer creates a state change notification.

type QueryOptions

type QueryOptions struct {
	Before    time.Time `json:"-"`
	Deleted   *bool     `json:"deleted,omitempty"`
	IDs       []uint64  `json:"-"`
	Limit     int       `json:"-"`
	ObjectIDs []uint64  `json:"object_ids"`
	OwnerIDs  []uint64  `json:"owner_ids"`
	Types     []Type    `json:"types"`
}

QueryOptions to narrow-down queries.

type Reaction

type Reaction struct {
	Deleted   bool
	ID        uint64
	ObjectID  uint64
	OwnerID   uint64
	Type      Type
	CreatedAt time.Time
	UpdatedAt time.Time
}

Reaction is the building block to express interactions on Objects/Posts.

func (*Reaction) MatchOpts

func (r *Reaction) MatchOpts(opts *QueryOptions) bool

MatchOpts indicates if the Reaction matches the given QueryOptions.

func (*Reaction) Validate

func (r *Reaction) Validate() error

Validate checks for semantic correctness.

type Service

type Service interface {
	service.Lifecycle

	Count(namespace string, opts QueryOptions) (uint, error)
	CountMulti(namespace string, opts QueryOptions) (CountsMap, error)
	Put(namespace string, reaction *Reaction) (*Reaction, error)
	Query(namespace string, opts QueryOptions) (List, error)
}

Service for Reaction interactions.

func MemService

func MemService() Service

MemService returns a memory based Service implementation.

func PostgresService

func PostgresService(db *sqlx.DB) Service

PostgresService returns a Postgres based Service inplementation.

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 resutls of heavy computation with sensible TTLs.

func InstrumentServiceMiddleware

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

InstrumentServiceMiddleware 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

type Source

type Source interface {
	source.Acker
	Consumer
	Producer
}

Source encapsulates state change notification operations.

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 apsects 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 with logging capabilities.

type StateChange

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

StateChange transports all information necessary to observe state changes.

type Type

type Type uint

Type is used to distinct Reactions by type.

const (
	TypeLike Type = iota + 1
	TypeLove
	TypeHaha
	TypeWow
	TypeSad
	TypeAngry
)

Supported Reaction types.

Jump to

Keyboard shortcuts

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