Documentation
¶
Index ¶
- Constants
- Variables
- func GetFieldValue(field string, data interface{}) (interface{}, error)
- func NewEvent(name string, data interface{}, moment time.Time) *evt
- func NoTags(e Event) (map[string]interface{}, error)
- type Aggregation
- type AggregationData
- type AggregationFnc
- type AggregationInc
- type Clock
- type Event
- type Granularity
- type GranularityComposite
- type LocalClock
- type Operation
- type OperationType
- type Pipeline
- type PipelineErrorHandler
- type PipelineResult
- type PipelineTagFnc
- type Storage
- type StorageEntry
Constants ¶
const ( OperationTypeInc = iota OperationTypeSet )
Variables ¶
var DefaultClock utcClock
DefaultClock is the default implementation of the clock.
Functions ¶
func GetFieldValue ¶
Types ¶
type Aggregation ¶
type Aggregation interface {
Aggregate(event Event, data *AggregationData) error
}
Aggregator produces an operation.
type AggregationData ¶
type AggregationData []Operation
type AggregationFnc ¶
type AggregationFnc struct {
// contains filtered or unexported fields
}
AggregationFnc increases a value of a field
func NewAggregationFnc ¶
func NewAggregationFnc(fnc func(e Event, data *AggregationData) error) *AggregationFnc
NewAggregationFnc creates a new instance of `AggregationFnc`.
func (*AggregationFnc) Aggregate ¶
func (agg *AggregationFnc) Aggregate(event Event, data *AggregationData) error
Aggregate calls fnc and returns its error
type AggregationInc ¶
AggregatorInc increases a value of a field
func NewAggregationInc ¶
func NewAggregationInc(field string, value ...int) *AggregationInc
NewAggregationInc creates a new instnace of the aggregation inc.
func (*AggregationInc) Aggregate ¶
func (agg *AggregationInc) Aggregate(event Event, data *AggregationData) error
Aggregate adds the `Field` with its `Value` to the `data`.
type Granularity ¶
type Granularity int
const ( GranularitySecond Granularity = iota GranularityMinute GranularityHour GranularityDay GranularityWeek GranularityMonth GranularityYear )
func (Granularity) RelativeTo ¶
func (g Granularity) RelativeTo(t, relativeTo time.Time) int
func (Granularity) String ¶
func (g Granularity) String() string
type GranularityComposite ¶
type GranularityComposite struct {
Record Granularity
Collection Granularity
}
GranularityComposite is the configuration added to the pipeline to be passed to the `Storage`.
The `Storage` create the collection and records according with this configuration.
type Operation ¶
type Operation struct {
Type OperationType
Field string
Value interface{}
}
func NewOperationInc ¶
func NewOperationSet ¶
type OperationType ¶
type OperationType = int
type Pipeline ¶
type Pipeline struct {
// Granularities is the set of granularity configurations that will be
// stored in the `Storage` set in this `Pipeline`.
Granularities []GranularityComposite
// Aggregations is the set of aggregations that will be applied in this
// `Pipeline`.
Aggregations []Aggregation
// Collection is the base name of the
Collection string
// TagFnc will evaluate the `Event` and recreate
TagFnc PipelineTagFnc
// Storage is the storaging system used in this `Pipeline`.
Storage Storage
// ErrorHandler is the handling error function that will be called if any
// error is triggered in the pipeline process.
ErrorHandler PipelineErrorHandler
}
Pipeline is responsible to receive an event and trigger each `Bucket` in sequence, aggregating each result and storing it using the `Storage`.
A Pipeline keeps an array of buckets that will be triggered when `Run` method is called.
func (*Pipeline) Run ¶
func (p *Pipeline) Run(e Event) (*PipelineResult, error)
Run triggers the processing of the buckets in order of registering.
Each `BucketResult` is synchronously stored in the `Storage` specified at the `Pipeline` "constructor".
The param `e` informed is the source of the data that will go through the pipeline.
type PipelineErrorHandler ¶
type PipelineErrorHandler func(aggregation Aggregation, err error) error
PipelineErrorHandler is called when an error is triggered in the pipeline process.
type PipelineResult ¶
type PipelineResult struct {
Data AggregationData
}
type PipelineTagFnc ¶
PipelineTagFunction receives an `Event` and set all keys beside the timeline which will, automatically, be set as _id.
func TagByField ¶
func TagByField(fields ...string) PipelineTagFnc
TagByField implements a `PipelineKeyFunction` that will only use field names (through reflection) to get the data value. It is a helper function for sugar coding.
type Storage ¶
type Storage interface {
Store(entry *StorageEntry) error
}
Storage will persists the `Result` obtained by a bucket.
type StorageEntry ¶
type StorageEntry struct {
Event Event
Collection string
Granularities []GranularityComposite
Result *PipelineResult
Keys map[string]interface{}
}