ehevent

package
v0.2.1-0...-14f66c8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Optional, standardized event structure + serialization format

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeserializeLines

func DeserializeLines(lines []byte) []string

func Serialize

func Serialize(events ...Event) []string

func SerializeLines

func SerializeLines(lines []string) []byte

helper. last line won't have \n after it. WARNING: you're responsible for making sure none of the lines have \n on it.

func SerializeOne

func SerializeOne(e Event) string

Types

type ErrUnsupportedEvent

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

func (*ErrUnsupportedEvent) Error

func (e *ErrUnsupportedEvent) Error() string

type Event

type Event interface {
	MetaType() string
	Meta() *EventMeta
}

event has type (event's name) and metadata (common attributes shared by all events)

func Deserialize

func Deserialize(input string, allocators Types) (Event, error)

deserialized one event from the line format. returns *ErrUnsupportedEvent* if event type not in *allocators*

type EventMeta

type EventMeta struct {
	DontUseTimeLogical     time.Time  `json:"t"`
	DontUseTimeOfRecording *time.Time `json:"tr,omitempty"`
	DontUseUserId          string     `json:"u,omitempty"`
}

common attributes for all events. timestamps are forced to UTC and rounded to millisecond precision. JSON fields are aggressively shortened for compactness

func Meta

func Meta(logical time.Time, userId string) EventMeta

creates event metadata with timestamp and user. timestamp is by default normalized to UTC and stored in only millisecond precision to conserve space when storing timestamps as a string.

func MetaBackdate

func MetaBackdate(logical time.Time, recorded time.Time, userId string) EventMeta

for when you need to backdate a user's event. i.e. something logical happened before it was finally recorded (usually *now*)

func MetaSystemUser

func MetaSystemUser(logical time.Time) EventMeta

for when the event doesn't have a known user, i.e. the user will be "system"

func MetaSystemUserBackdate

func MetaSystemUserBackdate(logical time.Time, recorded time.Time) EventMeta

same as MetaBackdate(), but with MetaSystemUser() semantics

func (*EventMeta) Serialize

func (e *EventMeta) Serialize(payload Event) string

func (*EventMeta) Time

func (e *EventMeta) Time() time.Time

"When did this happen" - logical timestamp. most times you'll use this (as opposed to time of recording)

func (*EventMeta) TimeOfRecording

func (e *EventMeta) TimeOfRecording() time.Time

"When was this event recorded". sometimes logical timestamp precedes time of recording:

  • sometimes you need to backdate events, e.g. importing old data where logical events happened years ago, but the events we're migrating to will be recorded *now*. only in these cases we have separate logical and recording timestamps. sensor data e.g. GPS time of fix vs. time the server received it can be even minutes later if end device has connectivity problems (or end device vs. server clock not in sync).
  • most times you're interested in TimestampLogical()
  • you'll almost always set time of recording to time.Now() when creating events

func (*EventMeta) UserId

func (e *EventMeta) UserId(systemUserId string) string

returns systemUserId if event was raised by "system", i.e. there's no explicit user

func (*EventMeta) UserIdOrEmptyIfSystem

func (e *EventMeta) UserIdOrEmptyIfSystem() string

type Types

type Types map[string]func() Event

type string => an allocator that returns pointers to concrete structs

Jump to

Keyboard shortcuts

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