event

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterContext

func RegisterContext(typ ContextType, ctor ContextContructor)

func RegisterNewContext

func RegisterNewContext(typ string, v interface{})

func RegisterType

func RegisterType(typ Type)

Types

type Context

type Context interface {
	Type() ContextType
	Values() map[string]interface{}
	Interface() interface{}
	Validate() bool
}

func NewContext

func NewContext(typ ContextType, v interface{}) Context

type ContextContructor

type ContextContructor func() Context

type ContextIterator

type ContextIterator interface {
	First() Context
	Next() Context
}

type ContextRegistry

type ContextRegistry map[ContextType]ContextContructor

type ContextType

type ContextType string
const (
	ContextInvalid ContextType = "invalid"
)

func GetContextType

func GetContextType(typ string) ContextType

type ContextValidator

type ContextValidator interface {
	Validate() bool
}

type Contexts

type Contexts map[string]Context

func (Contexts) Bind

func (c Contexts) Bind(v interface{})

func (Contexts) Get

func (c Contexts) Get(ct ContextType) (Context, bool)

func (Contexts) Iter

func (c Contexts) Iter() ContextIterator

func (Contexts) List

func (c Contexts) List() []string

func (Contexts) Map

func (c Contexts) Map() map[string]interface{}

func (Contexts) MarshalJSON

func (c Contexts) MarshalJSON() ([]byte, error)

func (*Contexts) UnmarshalJSON

func (c *Contexts) UnmarshalJSON(b []byte) error

func (Contexts) Visit

func (c Contexts) Visit(fn func(ctx Context))

type Event

type Event struct {
	ID         string `json:"id" structs:"id" mapstructure:"id"`
	TrackingID string `json:"trackingId" structs:"trackingID" mapstructure:"trackingID"`
	UserID     string `json:"userId,omitempty" structs:"userID,omitempty" mapstructure:"userID,omitempty"`
	Anonymous  bool   `json:"anonymous" structs:"anonymous" mapstructure:"anonymous"`
	GroupID    string `json:"groupId,omitempty" structs:"groupID,omitempty" mapstructure:"groupID,omitempty"`
	SessionID  string `json:"sessionId,omitempty" structs:"sessionID,omitempty" mapstructure:"sessionID,omitempty"`
	DeviceID   string `json:"deviceId,omitempty" structs:"deviceID,omitempty" mapstructure:"deviceID,omitempty"`

	Event          string    `json:"event" structs:"event" mapstructure:"event"`
	Type           Type      `json:"event_type" structs:"event_type" mapstructure:"event_type"`
	NonInteractive bool      `json:"nonInteractive,omitempty" structs:"nonInteractive,omitempty" mapstructure:"nonInteractive,omitempty"`
	Channel        string    `json:"channel,omitempty" structs:"channel,omitempty" mapstructure:"channel,omitempty"`
	Platform       string    `json:"platform,omitempty" structs:"platform,omitempty" mapstructure:"platform,omitempty"`
	Timestamp      time.Time `json:"timestamp" structs:"timestamp" mapstructure:"timestamp"`
	Context        Contexts  `json:"context,omitempty" structs:"context,omitempty" mapstructure:"context,omitempty"`
	// contains filtered or unexported fields
}

func Empty

func Empty() *Event

func New

func New(evt string, opts ...Option) *Event

func (*Event) Apply

func (e *Event) Apply(opts ...Option)

func (*Event) Render

func (e *Event) Render(opts ...Option) ([]byte, error)

func (*Event) SetContext

func (e *Event) SetContext(ctx Context)

func (*Event) SetContexts

func (e *Event) SetContexts(ctx ...Context)

func (*Event) Validate

func (e *Event) Validate() bool

type EventConstructor

type EventConstructor func(...Option) *Event

type EventRegistry

type EventRegistry map[Type]bool

type Option

type Option func(*Event)

func Anonymous

func Anonymous(b bool) Option

func Channel

func Channel(c string) Option

func DeviceID

func DeviceID(id string) Option

func EventType

func EventType(typ Type) Option

func GroupID

func GroupID(id string) Option

func Interactive

func Interactive() Option

func NonInteractive

func NonInteractive() Option

func Platform

func Platform(p string) Option

func SessionID

func SessionID(id string) Option

func TrackingID

func TrackingID(id string) Option

func UserID

func UserID(id string) Option

func WithContext

func WithContext(ctx Context) Option

func WithContexts

func WithContexts(ctx ...Context) Option

func WithValidator

func WithValidator(v Validator) Option

type Rule

type Rule func(*Event) bool

func ContextContains

func ContextContains(ct ContextType, k string, nonZero bool) Rule

func ContextValid

func ContextValid(ct ContextType) Rule

func HasContext

func HasContext(ct ContextType) Rule

func HasID

func HasID(id string) Rule

type Type

type Type string
const EventTypeEvent Type = "event"

type Validator

type Validator map[string]Rule

func NewValidator

func NewValidator(opts ...ValidatorOption) Validator

func (Validator) Validate

func (v Validator) Validate(evt *Event) bool

type ValidatorOption

type ValidatorOption func(Validator)

func WithRule

func WithRule(n string, rule Rule) ValidatorOption

func WithRules

func WithRules(m map[string]Rule) ValidatorOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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