messaging

package
v0.0.0-...-a671794 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler = common.ErrorHandler

ErrorHandler handles an error.

type Events

type Events interface {
	// NewMessageSent dispatches a MessageSent event.
	NewMessageSent(ctx context.Context, event MessageSent) error
}

Events dispatches message events.

type IDGenerator

type IDGenerator interface {
	// Generate generates a new ID.
	Generate() (string, error)
}

IDGenerator generates a new ID.

type InMemoryStore

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

InMemoryStore keeps messages in the memory. Use it in tests or for development/demo purposes.

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore returns a new inmemory message store.

func (*InMemoryStore) All

func (s *InMemoryStore) All(ctx context.Context) ([]Message, error)

All returns all messages.

func (*InMemoryStore) Get

func (s *InMemoryStore) Get(ctx context.Context, id string) (Message, error)

Get returns a single message by its ID.

func (*InMemoryStore) Store

func (s *InMemoryStore) Store(ctx context.Context, message Message) error

Store stores a message.

type LogEventHandler

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

LogEventHandler handles message events and logs them.

func NewLogEventHandler

func NewLogEventHandler(logger Logger) LogEventHandler

NewLogEventHandler returns a new LogEventHandler instance.

func (LogEventHandler) NewMessageSent

func (h LogEventHandler) NewMessageSent(ctx context.Context, event MessageSent) error

NewMessageSent logs a MessageSent event.

type Logger

type Logger = common.Logger

Logger is the fundamental interface for all log operations.

type Message

type Message struct {
	ID   string
	Text string
}

Message describing a message and its content

type MessageSent

type MessageSent struct {
	ID   string
	Text string
}

MessageSent event is triggered when a new message created.

type NotFoundError

type NotFoundError struct {
	ID string
}

NotFoundError is returned if a message cannot be found.

func (NotFoundError) Details

func (e NotFoundError) Details() []interface{}

Details returns error details.

func (NotFoundError) Error

func (NotFoundError) Error() string

Error implements the error interface.

func (NotFoundError) NotFound

func (NotFoundError) NotFound() bool

NotFound tells a client that this error is related to a resource being not found. Can be used to translate the error to eg. status code.

func (NotFoundError) ServiceError

func (NotFoundError) ServiceError() bool

ServiceError tells the transport layer whether this error should be translated into the transport format or an internal error should be returned instead.

type ReadOnlyStore

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

ReadOnlyStore cannot be modified.

func NewReadOnlyStore

func NewReadOnlyStore(store Store) *ReadOnlyStore

NewReadOnlyStore returns a new read-only message store instance.

func (*ReadOnlyStore) All

func (s *ReadOnlyStore) All(ctx context.Context) ([]Message, error)

All returns all messages.

func (*ReadOnlyStore) Get

func (s *ReadOnlyStore) Get(ctx context.Context, id string) (Message, error)

Get returns a single message by its ID.

func (*ReadOnlyStore) Store

func (*ReadOnlyStore) Store(ctx context.Context, message Message) error

Store stores a mesage.

type Service

type Service interface {
	// CreateMessage adds a new message to the message list.
	CreateMessage(ctx context.Context, text string) (id string, err error)

	// ListMessages returns the list of messages.
	ListMessages(ctx context.Context) (messages []Message, err error)

	// GetMessage returns the message by id.
	GetMessage(ctx context.Context, id string) (message Message, err error)
}

Service manages a list of messages.

func NewService

func NewService(idgenerator IDGenerator, store Store, events Events) Service

NewService returns a new Service.

type Store

type Store interface {
	// Store stores a message.
	Store(ctx context.Context, message Message) error

	// All returns all messages.
	All(ctx context.Context) ([]Message, error)

	// Get returns a single message by its ID.
	Get(ctx context.Context, id string) (Message, error)
}

Store provides message persistence.

Jump to

Keyboard shortcuts

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