Documentation ¶
Index ¶
- Constants
- Variables
- func IsEmptySource(err error) bool
- func IsInvalidAttachment(err error) bool
- func IsInvalidObject(err error) bool
- func IsMissingReference(err error) bool
- func IsNamespaceNotFound(err error) bool
- func IsNotFound(err error) bool
- type Attachment
- type Consumer
- type Contents
- type Counts
- type CountsMap
- type Error
- type List
- type Map
- type Object
- type Private
- type Producer
- type QueryOptions
- type Restrictions
- 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 State
- type StateChange
- type Visibility
Constants ¶
const ( AttachmentTypeText = "text" AttachmentTypeURL = "url" )
Attachment variants available for Objects.
const DefaultLanguage = "en"
DefaultLanguage is used when no lang is provided for object content.
const TypeComment = "tg_comment"
Variables ¶
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 ¶
IsEmptySource indicates if err is ErrEmptySource.
func IsInvalidAttachment ¶
IsInvalidAttachment indicates if err is ErrInvalidAttachment.
func IsInvalidObject ¶
IsInvalidObject indicates if err is ErrInvalidObject.
func IsMissingReference ¶
IsMissingReference indicates if err is ErrMissingReference.
func IsNamespaceNotFound ¶
IsNamespaceNotFound indicates if err is ErrNamespaceNotFound.
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 Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps common Object errors.
type List ¶
type List []*Object
List is an Object collection.
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.
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 ¶
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
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 raps the next Source logging capabilities.
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.