events

package
v0.0.0-...-2819d24 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

func OnCreateFeed

func OnCreateFeed(callback func(CreatedFeedMessage)) error

func PublishCreatedFeed

func PublishCreatedFeed(cxt context.Context, feed *models.Feed) error

func SetEventStore

func SetEventStore(store EventStore)

func SubscribeCreatedFeed

func SubscribeCreatedFeed(cxt context.Context) (<-chan CreatedFeedMessage, error)

Types

type CreatedFeedMessage

type CreatedFeedMessage struct {
	Id          string    `json:"id"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
}

func (*CreatedFeedMessage) Type

func (createdFeedMessage *CreatedFeedMessage) Type() string

type EventStore

type EventStore interface {
	Close()
	PublishCreatedFeed(cxt context.Context, feed *models.Feed) error
	SubscribeCreatedFeed(cxt context.Context) (<-chan CreatedFeedMessage, error)
	OnCreateFeed(callback func(CreatedFeedMessage)) error
}

type Message

type Message interface {
	Type() string
}

type NatsEventStore

type NatsEventStore struct {
	Connection      *natsio.Conn
	FeedCreatedSub  *natsio.Subscription
	FeedCreatedChan chan CreatedFeedMessage
}

func NewNats

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

func (*NatsEventStore) Close

func (nats *NatsEventStore) Close()

func (*NatsEventStore) OnCreateFeed

func (nats *NatsEventStore) OnCreateFeed(callback func(CreatedFeedMessage)) (err error)

func (*NatsEventStore) PublishCreatedFeed

func (nats *NatsEventStore) PublishCreatedFeed(cxt context.Context, feed *models.Feed) error

func (*NatsEventStore) SubscribeCreatedFeed

func (nats *NatsEventStore) SubscribeCreatedFeed(cxt context.Context) (<-chan CreatedFeedMessage, error)

Jump to

Keyboard shortcuts

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