events

package
v0.0.0-...-133dcc5 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 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()

Methods

func OnCreateFeed

func OnCreateFeed(f func(CreatedFeedMessage)) error

func PublishCreatedFeed

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

func SetEventStore

func SetEventStore(store EventStore)

func SubscribeCreatedFeed

func SubscribeCreatedFeed(ctx 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"`
}

Struct that will be transmitted through the NATS system

func (CreatedFeedMessage) Type

func (m CreatedFeedMessage) Type() string

Message to Event Feed Created

type EventStore

type EventStore interface {
	Close()
	// Publish new feed event
	PublishCreatedFeed(ctx context.Context, feed *models.Feed) error
	// Subscribe to feed event
	SubscribeCreatedFeed(ctx context.Context) (<-chan CreatedFeedMessage, error)
	// Callback when new feed is created
	OnCreateFeed(f func(CreatedFeedMessage)) error
}

Abstract implementation of NATS

type Message

type Message interface {
	Type() string
}

Dependency inversion interface Abstract implementation

type NatsEventStore

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

func NewNats

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

Methods of NatsEventStore Constructor

func (*NatsEventStore) Close

func (n *NatsEventStore) Close()

Close Method

func (*NatsEventStore) OnCreateFeed

func (n *NatsEventStore) OnCreateFeed(f func(CreatedFeedMessage)) (err error)

Closure to subscribe

func (*NatsEventStore) PublishCreatedFeed

func (n *NatsEventStore) PublishCreatedFeed(ctx context.Context, feed *models.Feed) error

Method Publish Created Feed to services connected to NATS

func (*NatsEventStore) SubscribeCreatedFeed

func (n *NatsEventStore) SubscribeCreatedFeed(ctx context.Context) (<-chan CreatedFeedMessage, error)

Subscription Channel

Jump to

Keyboard shortcuts

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