Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Events ¶
type Events interface { // NewMessageSent dispatches a MessageSent event. NewMessageSent(ctx context.Context, event MessageSent) error }
Events dispatches message events.
type IDGenerator ¶
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.
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 MessageSent ¶
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.
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.