connection

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptySource       = errors.New("empty source")
	ErrInvalidConnection = errors.New("invalid connection")
)

Common errors for Connection service implementations and validations.

Functions

func IsEmptySource

func IsEmptySource(err error) bool

IsEmptySource indicates if err is ErrEmptySource

func IsInvalidConnection

func IsInvalidConnection(err error) bool

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 Error

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

func (Error) Error

func (e Error) Error() string

type List

type List []*Connection

List is a collection of Connections.

func (List) FromIDs

func (l List) FromIDs() []uint64

FromIDs returns the extracted FromID of all connections as list.

func (List) Len

func (l List) Len() int

func (List) Less

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

func (List) OtherIDs

func (l List) OtherIDs(origin uint64) []uint64

OtherIDs returns the user ids not being the origin.

func (List) Swap

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

func (List) ToIDs

func (l List) ToIDs() []uint64

ToIDs returns the extracted ToID of all connections as list.

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

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 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 Source

type Source interface {
	source.Acker
	Consumer
	Producer
}

Source encapsulates state change notification 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 with logging capabilities.

type State

type State string

State of a connection request.

const (
	StateConfirmed State = "confirmed"
	StatePending   State = "pending"
	StateRejected  State = "rejected"
)

Supported states for connections.

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.

type Type

type Type string

Type of a user relation.

const (
	TypeFollow Type = "follow"
	TypeFriend Type = "friend"
)

Supported types for connections.

Jump to

Keyboard shortcuts

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