object

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

Documentation

Index

Constants

View Source
const (
	AttachmentTypeText = "text"
	AttachmentTypeURL  = "url"
)

Attachment variants available for Objects.

View Source
const DefaultLanguage = "en"

DefaultLanguage is used when no lang is provided for object content.

View Source
const TypeComment = "tg_comment"

Variables

View Source
var (
	ErrEmptySource       = errors.New("empty source")
	ErrInvalidAttachment = errors.New("invalid attachment")
	ErrInvalidObject     = errors.New("invalid object")
	ErrMissingReference  = errors.New("referenced object missing")
	ErrNamespaceNotFound = errors.New("namespace not found")
	ErrNotFound          = errors.New("object not found")
)

Common errors for Object validation and Service.

Functions

func IsEmptySource

func IsEmptySource(err error) bool

IsEmptySource indicates if err is ErrEmptySource.

func IsInvalidAttachment

func IsInvalidAttachment(err error) bool

IsInvalidAttachment indicates if err is ErrInvalidAttachment.

func IsInvalidObject

func IsInvalidObject(err error) bool

IsInvalidObject indicates if err is ErrInvalidObject.

func IsMissingReference

func IsMissingReference(err error) bool

IsMissingReference indicates if err is ErrMissingReference.

func IsNamespaceNotFound

func IsNamespaceNotFound(err error) bool

IsNamespaceNotFound indicates if err is ErrNamespaceNotFound.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound indicates if err is ErrNotFound.

Types

type Attachment

type Attachment struct {
	Contents Contents `json:"contents"`
	Name     string   `json:"name"`
	Type     string   `json:"type"`
}

Attachment is typed media which belongs to an Object.

func TextAttachment

func TextAttachment(name string, contents Contents) Attachment

TextAttachment returns an Attachment of type Text.

func URLAttachment

func URLAttachment(name string, contents Contents) Attachment

URLAttachment returns an Attachment of type URL.

func (Attachment) Validate

func (a Attachment) Validate() error

Validate returns an error if a Attachment constraint is not full-filled.

type Consumer

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

Consumer observes state changes.

type Contents

type Contents map[string]string

Contents is the mapping of content to locale.

func (Contents) Validate

func (c Contents) Validate() error

Validate performs semantic checks on the localisation fields.

type Counts

type Counts struct {
	Comments uint64
}

Counts bundles all Object counts by type.

type CountsMap

type CountsMap map[uint64]Counts

CountsMap is the association of an object id to Counts.

type Error

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

Error wraps common Object errors.

func (Error) Error

func (e Error) Error() string

type List

type List []*Object

List is an Object collection.

func (List) Len

func (l List) Len() int

func (List) Less

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

func (List) OwnerIDs

func (l List) OwnerIDs() []uint64

OwnerIDs returns all user ids of the associated object owners.

func (List) Swap

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

type Map

type Map map[uint64]*Object

Map is an Object collection indexed by id.

type Object

type Object struct {
	Attachments  []Attachment  `json:"attachments"`
	CreatedAt    time.Time     `json:"created_at"`
	Deleted      bool          `json:"deleted"`
	ExternalID   string        `json:"external_id"`
	ID           uint64        `json:"id"`
	Latitude     float64       `json:"latitude"`
	Location     string        `json:"location"`
	Longitude    float64       `json:"longitude"`
	ObjectID     uint64        `json:"object_id"`
	Owned        bool          `json:"owned"`
	OwnerID      uint64        `json:"owner_id"`
	Private      *Private      `json:"private,omitempty"`
	Restrictions *Restrictions `json:"restrictions,omitempty"`
	Tags         []string      `json:"tags"`
	Type         string        `json:"type"`
	UpdatedAt    time.Time     `json:"updated_at"`
	Visibility   Visibility    `json:"visibility"`
}

Object is a generic building block to express different domains like Posts, Albums with their dependend objects.

func (*Object) MatchOpts

func (o *Object) MatchOpts(opts *QueryOptions) bool

MatchOpts indicates if the Object matches the given QueryOptions.

func (*Object) Validate

func (o *Object) Validate() error

Validate returns an error if a constraint on the Object is not full-filled.

type Private

type Private struct {
	State   State `json:"state"`
	Visible bool  `json:"visible"`
}

Private is the bucket for protected fields on an Object.

type Producer

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

Producer creates a state change notification.

type QueryOptions

type QueryOptions struct {
	After        time.Time    `json:"-"`
	Before       time.Time    `json:"-"`
	Deleted      bool         `json:"deleted,omitempty"`
	ExternalIDs  []string     `json:"-"`
	ID           *uint64      `json:"id,omitempty"`
	Limit        int          `json:"-"`
	ObjectIDs    []uint64     `json:"object_ids,omitempty"`
	OwnerIDs     []uint64     `json:"owner_ids,omitempty"`
	Owned        *bool        `json:"owned,omitempty"`
	Tags         []string     `json:"tags,omitempty"`
	Types        []string     `json:"types,omitempty"`
	Visibilities []Visibility `json:"visibilities,omitempty"`
}

QueryOptions are passed to narrow down query for objects.

type Restrictions

type Restrictions struct {
	Comment bool `json:"comment"`
	Like    bool `json:"like"`
	Report  bool `json:"report"`
}

Restrictions is the composite to regulate common interactions on Posts.

type Service

type Service interface {
	service.Lifecycle

	Count(namespace string, opts QueryOptions) (int, error)
	CountMulti(namespace string, objectIds ...uint64) (CountsMap, error)
	Put(namespace string, object *Object) (*Object, error)
	Query(namespace string, opts QueryOptions) (List, error)
}

Service for object 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

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 raps the next Source logging capabilities.

type State

type State uint8

State reflects the progress of an object through a review process.

const (
	StatePending State = iota
	StateConfirmed
	StateDeclined
)

State variants available for Objects.

type StateChange

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

StateChange transports all information necessary to observe state change.

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 Objects.

Jump to

Keyboard shortcuts

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