Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptySource = errors.New("empty source") ErrInvalidConnection = errors.New("invalid connection") )
Common errors for Connection service implementations and validations.
Functions ¶
func IsEmptySource ¶
IsEmptySource indicates if err is ErrEmptySource
func IsInvalidConnection ¶
IsInvalidConnection indicates if err is ErrInvalidConnection.
Types ¶
type Connection ¶
type Connection struct { Enabled bool `json:"enabled"` FromID uint64 `json:"user_from_id"` State State `json:"state"` ToID uint64 `json:"user_to_id"` Type Type `json:"type"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Connection represents a relation between two users.
func (*Connection) MatchOpts ¶
func (c *Connection) MatchOpts(opts *QueryOptions) bool
MatchOpts indicates if the Connection matches the given QueryOptions.
func (Connection) Validate ¶
func (c Connection) Validate() error
Validate performs checks on the Connection values for completeness and correctness.
type Consumer ¶
type Consumer interface {
Consume() (*StateChange, error)
}
Consumer observes state changes.
type List ¶
type List []*Connection
List is a collection of Connections.
type Producer ¶
type Producer interface {
Propagate(namespace string, old, new *Connection) (string, error)
}
Producer creates state change notifications.
type QueryOptions ¶
type QueryOptions struct { After time.Time `json:"-"` Before time.Time `json:"-"` Enabled *bool `json:"enabled,omitempty"` FromIDs []uint64 `json:"from_ids,omitempty"` Limit int `json:"-"` States []State `json:"states,omitempty"` ToIDs []uint64 `json:"to_ids,omitempty"` Types []Type `json:"types,omitempty"` }
QueryOptions are used to narrow down Connection queries.
type Service ¶
type Service interface { service.Lifecycle Count(namespace string, opts QueryOptions) (int, error) Friends(namespace string, origin uint64) (List, error) Put(namespace string, connection *Connection) (*Connection, error) Query(namespace string, opts QueryOptions) (List, error) }
Service for connection 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 InstrumentServiceMiddleware ¶
func InstrumentServiceMiddleware( component, store string, errCount kitmetrics.Counter, opCount kitmetrics.Counter, opLatency *prometheus.HistogramVec, ) ServiceMiddleware
InstrumentServiceMiddleware observes key aspects 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 with logging capabilities.
type StateChange ¶
type StateChange struct { AckID string ID string Namespace string New *Connection Old *Connection SentAt time.Time }
StateChange transports all information necessary to observe state changes.