Documentation
¶
Index ¶
- Constants
- func GetEventLogger() *zerolog.Logger
- func SetEventLogger(l *zerolog.Logger)
- type Event
- type EventMock
- func (mock *EventMock) Ack()
- func (mock *EventMock) AckCalls() []struct{}
- func (mock *EventMock) Clone(ctx context.Context) (Event, error)
- func (mock *EventMock) CloneCalls() []struct{ ... }
- func (mock *EventMock) Context() context.Context
- func (mock *EventMock) ContextCalls() []struct{}
- func (mock *EventMock) Created() time.Time
- func (mock *EventMock) CreatedCalls() []struct{}
- func (mock *EventMock) DeepCopy() error
- func (mock *EventMock) DeepCopyCalls() []struct{}
- func (mock *EventMock) Evaluate(expression interface{}) (interface{}, interface{}, string)
- func (mock *EventMock) EvaluateCalls() []struct{ ... }
- func (mock *EventMock) GetPathValue(path string) (interface{}, interface{}, string)
- func (mock *EventMock) GetPathValueCalls() []struct{ ... }
- func (mock *EventMock) Id() string
- func (mock *EventMock) IdCalls() []struct{}
- func (mock *EventMock) Metadata() map[string]interface{}
- func (mock *EventMock) MetadataCalls() []struct{}
- func (mock *EventMock) Nack(err error)
- func (mock *EventMock) NackCalls() []struct{ ... }
- func (mock *EventMock) Payload() interface{}
- func (mock *EventMock) PayloadCalls() []struct{}
- func (mock *EventMock) SetContext(ctx context.Context) error
- func (mock *EventMock) SetContextCalls() []struct{ ... }
- func (mock *EventMock) SetMetadata(metadata map[string]interface{}) error
- func (mock *EventMock) SetMetadataCalls() []struct{ ... }
- func (mock *EventMock) SetPathValue(path string, val interface{}, createPath bool) (interface{}, string, error)
- func (mock *EventMock) SetPathValueCalls() []struct{ ... }
- func (mock *EventMock) SetPayload(payload interface{}) error
- func (mock *EventMock) SetPayloadCalls() []struct{ ... }
- func (mock *EventMock) Tenant() tenant.Id
- func (mock *EventMock) TenantCalls() []struct{}
- type EventOption
- func FailOnAck(t *testing.T) EventOption
- func FailOnNack(t *testing.T) EventOption
- func WithAck(handledFn func(Event), errFn func(Event, error)) EventOption
- func WithId(eid string) EventOption
- func WithMetadata(metadata map[string]interface{}) EventOption
- func WithMetadataKeyValue(key string, val interface{}) EventOption
- func WithOtelTracing(spanName string) EventOption
- func WithTenant(tid tenant.Id) EventOption
- func WithTracePayloadOnNack(tracePayloadOnNack bool) EventOption
- type NoAckHandlersError
Constants ¶
const ( PAYLOAD = "payload" METADATA = "metadata" TRACE = "trace" TENANT = "tenant" TIMESTAMP = "timestamp" )
Variables ¶
This section is empty.
Functions ¶
func GetEventLogger ¶ added in v0.4.0
func SetEventLogger ¶ added in v0.4.0
Types ¶
type Event ¶
type Event interface { //Get the event payload Payload() interface{} //Get event id Id() string //Get the event metadata Metadata() map[string]interface{} //Get the event tenant Tenant() tenant.Id //Get the event context Context() context.Context //Get the event creation time Created() time.Time //Set the event payload //Will return an error if the event is done SetPayload(payload interface{}) error //Set the event metadata //Will return an error if the event is done SetMetadata(metadata map[string]interface{}) error // SetPathValue sets object value at path in either payload or metadata and returns its parent // object and parent key if those exist SetPathValue(path string, val interface{}, createPath bool) (interface{}, string, error) // GetPathValue finds object at path in either payload or metadata and returns such object // if one exists along with its parent object and parent key if those exist GetPathValue(path string) (interface{}, interface{}, string) //Evaluate processes expressions like "my {payload.some.feature} thing", if the expression is a // simple path like "{payload.some.feature}" it will act like GetPathValue() Evaluate(expression interface{}) (interface{}, interface{}, string) //Replace the current event context //Will return an error if the event is done SetContext(ctx context.Context) error //Acknowledge that the event is handled successfully //Further actions on the event are no longer possible Ack() //Acknowledge that there is an error handling the event //Further actions on the event are no longer possible Nack(err error) //Create a child event with payload shallow-copied //Clone fails and return an error if the event is already acknowledged Clone(ctx context.Context) (Event, error) //Deep copy event payload and metadata DeepCopy() error }
type EventMock ¶
type EventMock struct { // AckFunc mocks the Ack method. AckFunc func() // CloneFunc mocks the Clone method. CloneFunc func(ctx context.Context) (Event, error) // ContextFunc mocks the Context method. ContextFunc func() context.Context // CreatedFunc mocks the Created method. CreatedFunc func() time.Time // DeepCopyFunc mocks the DeepCopy method. DeepCopyFunc func() error // EvaluateFunc mocks the Evaluate method. EvaluateFunc func(expression interface{}) (interface{}, interface{}, string) // GetPathValueFunc mocks the GetPathValue method. GetPathValueFunc func(path string) (interface{}, interface{}, string) // IdFunc mocks the Id method. IdFunc func() string // MetadataFunc mocks the Metadata method. MetadataFunc func() map[string]interface{} // NackFunc mocks the Nack method. NackFunc func(err error) // PayloadFunc mocks the Payload method. PayloadFunc func() interface{} // SetContextFunc mocks the SetContext method. SetContextFunc func(ctx context.Context) error // SetMetadataFunc mocks the SetMetadata method. SetMetadataFunc func(metadata map[string]interface{}) error // SetPathValueFunc mocks the SetPathValue method. SetPathValueFunc func(path string, val interface{}, createPath bool) (interface{}, string, error) // SetPayloadFunc mocks the SetPayload method. SetPayloadFunc func(payload interface{}) error // TenantFunc mocks the Tenant method. TenantFunc func() tenant.Id // contains filtered or unexported fields }
EventMock is a mock implementation of Event.
func TestSomethingThatUsesEvent(t *testing.T) { // make and configure a mocked Event mockedEvent := &EventMock{ AckFunc: func() { panic("mock out the Ack method") }, CloneFunc: func(ctx context.Context) (Event, error) { panic("mock out the Clone method") }, ContextFunc: func() context.Context { panic("mock out the Context method") }, CreatedFunc: func() time.Time { panic("mock out the Created method") }, DeepCopyFunc: func() error { panic("mock out the DeepCopy method") }, EvaluateFunc: func(expression interface{}) (interface{}, interface{}, string) { panic("mock out the Evaluate method") }, GetPathValueFunc: func(path string) (interface{}, interface{}, string) { panic("mock out the GetPathValue method") }, IdFunc: func() string { panic("mock out the Id method") }, MetadataFunc: func() map[string]interface{} { panic("mock out the Metadata method") }, NackFunc: func(err error) { panic("mock out the Nack method") }, PayloadFunc: func() interface{} { panic("mock out the Payload method") }, SetContextFunc: func(ctx context.Context) error { panic("mock out the SetContext method") }, SetMetadataFunc: func(metadata map[string]interface{}) error { panic("mock out the SetMetadata method") }, SetPathValueFunc: func(path string, val interface{}, createPath bool) (interface{}, string, error) { panic("mock out the SetPathValue method") }, SetPayloadFunc: func(payload interface{}) error { panic("mock out the SetPayload method") }, TenantFunc: func() tenant.Id { panic("mock out the Tenant method") }, } // use mockedEvent in code that requires Event // and then make assertions. }
func (*EventMock) AckCalls ¶
func (mock *EventMock) AckCalls() []struct { }
AckCalls gets all the calls that were made to Ack. Check the length with:
len(mockedEvent.AckCalls())
func (*EventMock) CloneCalls ¶
CloneCalls gets all the calls that were made to Clone. Check the length with:
len(mockedEvent.CloneCalls())
func (*EventMock) ContextCalls ¶
func (mock *EventMock) ContextCalls() []struct { }
ContextCalls gets all the calls that were made to Context. Check the length with:
len(mockedEvent.ContextCalls())
func (*EventMock) CreatedCalls ¶ added in v0.4.0
func (mock *EventMock) CreatedCalls() []struct { }
CreatedCalls gets all the calls that were made to Created. Check the length with:
len(mockedEvent.CreatedCalls())
func (*EventMock) DeepCopyCalls ¶ added in v1.1.0
func (mock *EventMock) DeepCopyCalls() []struct { }
DeepCopyCalls gets all the calls that were made to DeepCopy. Check the length with:
len(mockedEvent.DeepCopyCalls())
func (*EventMock) EvaluateCalls ¶ added in v1.1.0
func (mock *EventMock) EvaluateCalls() []struct { Expression interface{} }
EvaluateCalls gets all the calls that were made to Evaluate. Check the length with:
len(mockedEvent.EvaluateCalls())
func (*EventMock) GetPathValue ¶
GetPathValue calls GetPathValueFunc.
func (*EventMock) GetPathValueCalls ¶
GetPathValueCalls gets all the calls that were made to GetPathValue. Check the length with:
len(mockedEvent.GetPathValueCalls())
func (*EventMock) IdCalls ¶ added in v0.9.0
func (mock *EventMock) IdCalls() []struct { }
IdCalls gets all the calls that were made to Id. Check the length with:
len(mockedEvent.IdCalls())
func (*EventMock) MetadataCalls ¶
func (mock *EventMock) MetadataCalls() []struct { }
MetadataCalls gets all the calls that were made to Metadata. Check the length with:
len(mockedEvent.MetadataCalls())
func (*EventMock) NackCalls ¶
NackCalls gets all the calls that were made to Nack. Check the length with:
len(mockedEvent.NackCalls())
func (*EventMock) PayloadCalls ¶
func (mock *EventMock) PayloadCalls() []struct { }
PayloadCalls gets all the calls that were made to Payload. Check the length with:
len(mockedEvent.PayloadCalls())
func (*EventMock) SetContext ¶
SetContext calls SetContextFunc.
func (*EventMock) SetContextCalls ¶
SetContextCalls gets all the calls that were made to SetContext. Check the length with:
len(mockedEvent.SetContextCalls())
func (*EventMock) SetMetadata ¶
SetMetadata calls SetMetadataFunc.
func (*EventMock) SetMetadataCalls ¶
SetMetadataCalls gets all the calls that were made to SetMetadata. Check the length with:
len(mockedEvent.SetMetadataCalls())
func (*EventMock) SetPathValue ¶
func (mock *EventMock) SetPathValue(path string, val interface{}, createPath bool) (interface{}, string, error)
SetPathValue calls SetPathValueFunc.
func (*EventMock) SetPathValueCalls ¶
SetPathValueCalls gets all the calls that were made to SetPathValue. Check the length with:
len(mockedEvent.SetPathValueCalls())
func (*EventMock) SetPayload ¶
SetPayload calls SetPayloadFunc.
func (*EventMock) SetPayloadCalls ¶
func (mock *EventMock) SetPayloadCalls() []struct { Payload interface{} }
SetPayloadCalls gets all the calls that were made to SetPayload. Check the length with:
len(mockedEvent.SetPayloadCalls())
func (*EventMock) TenantCalls ¶ added in v0.4.0
func (mock *EventMock) TenantCalls() []struct { }
TenantCalls gets all the calls that were made to Tenant. Check the length with:
len(mockedEvent.TenantCalls())
type EventOption ¶
type EventOption func(*event) error
func FailOnAck ¶
func FailOnAck(t *testing.T) EventOption
func FailOnNack ¶
func FailOnNack(t *testing.T) EventOption
func WithAck ¶
func WithAck(handledFn func(Event), errFn func(Event, error)) EventOption
event acknowledge option with two completion functions, handledFn and errFn. An event with acknowledgement option will be notified through the handledFn when an event is handled, or through the errFn when there is an error handling it. An event is considered handled when it and all its child events (derived from the Clone function) have called the Ack function. An event is considered to have an error if it or any of its child events (derived from the Clone function) has called the Nack function. An event can also error out if it does not receive all the acknowledgements before the context timeout/cancellation.
func WithId ¶ added in v0.9.0
func WithId(eid string) EventOption
func WithMetadata ¶
func WithMetadata(metadata map[string]interface{}) EventOption
func WithMetadataKeyValue ¶ added in v0.6.0
func WithMetadataKeyValue(key string, val interface{}) EventOption
func WithOtelTracing ¶ added in v0.7.0
func WithOtelTracing(spanName string) EventOption
WithOtelTracing enables opentelemtry tracing for the event
func WithTenant ¶ added in v0.4.0
func WithTenant(tid tenant.Id) EventOption
func WithTracePayloadOnNack ¶ added in v0.7.0
func WithTracePayloadOnNack(tracePayloadOnNack bool) EventOption
type NoAckHandlersError ¶
type NoAckHandlersError struct { }
func (*NoAckHandlersError) Error ¶
func (e *NoAckHandlersError) Error() string