event

package
v0.0.0-...-8a2f722 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close closes the EventStore

func OnMeowCreated

func OnMeowCreated(f func(MeowCreatedMessage)) error

OnMeowCreated executes a function when MeowCreated

func PublishMeowCreated

func PublishMeowCreated(meow schema.Meow) error

PublishMeowCreated send an event to all subscribers

func SetEventStore

func SetEventStore(es EventStore)

SetEventStore sets the EventStore

func SubscribeMeowCreated

func SubscribeMeowCreated() (<-chan MeowCreatedMessage, error)

SubscribeMeowCreated adds a new subscriber for the event

Types

type EventStore

type EventStore interface {
	Close()
	PublishMeowCreated(meow schema.Meow) error
	SubscribeMeowCreated() (<-chan MeowCreatedMessage, error)
	OnMeowCreated(f func(MeowCreatedMessage)) error
}

EventStore is an interface for store events

type MeowCreatedMessage

type MeowCreatedMessage struct {
	ID        string
	Body      string
	CreatedAt time.Time
}

MeowCreatedMessage is the event created when the Meow is created

func (*MeowCreatedMessage) Key

func (m *MeowCreatedMessage) Key() string

Key returns the key of event created

type Message

type Message interface {
	Key() string
}

Message represents a message event

type NatsEventStore

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

NatsEventStore represents the EventStore that will be used into nats

func NewNats

func NewNats(url string) (*NatsEventStore, error)

NewNats creates a new connections to Nats server

func (*NatsEventStore) Close

func (e *NatsEventStore) Close()

Close closes the connection, unsubscribes the subscription and closes the channel

func (*NatsEventStore) OnMeowCreated

func (e *NatsEventStore) OnMeowCreated(f func(MeowCreatedMessage)) (err error)

OnMeowCreated executes a function on after Event MeoewCreatedMessage was fired

func (*NatsEventStore) PublishMeowCreated

func (e *NatsEventStore) PublishMeowCreated(meow schema.Meow) error

PublishMeowCreated publishes the Event to nats Subscribers

func (*NatsEventStore) SubscribeMeowCreated

func (e *NatsEventStore) SubscribeMeowCreated() (<-chan MeowCreatedMessage, error)

SubscribeMeowCreated creates a subscriber for the event

Jump to

Keyboard shortcuts

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