services

package
v0.0.0-...-6022d19 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatMessage

func FormatMessage(user, friend, message string) string

Formats a user message

func SendUserMessage

func SendUserMessage(messageService MessageService, message Message) error

Formats and sends a user message

Types

type Message

type Message struct {
	User, Friend, Text string
	Id                 int
}

Encapsulates a message from a User to her or his Friend with message Text

func CheckMessages

func CheckMessages(messageService MessageService,
	userTo string) ([]Message, error)

Checks user messages, with the given MessageService and user id

type MessageService

type MessageService interface {

	// Gets the messages that have been sent to a user
	GetMessages(userTo string) ([]Message, error)

	// Send a message to a user
	SendMessage(userFrom, userTo, formattedMessage string) error
}

Interface for sending messages

func GetMessageService

func GetMessageService() MessageService

Gets an the MessageService if already instantiated, or creates a new one

type MockMessageService

type MockMessageService map[string][]Message

Mock object that saves the messages in app memory

func (MockMessageService) GetMessages

func (service MockMessageService) GetMessages(userTo string) ([]Message, error)

Gets messages from app memory

func (MockMessageService) SendMessage

func (service MockMessageService) SendMessage(userFrom, userTo,
	text string) error

Saves messages to app memory

type SQLMessagingService

type SQLMessagingService struct{ DBConn *sql.DB }

An implemementation of MessageService using a SQL database

func (SQLMessagingService) GetMessages

func (service SQLMessagingService) GetMessages(userTo string) ([]Message,
	error)

Gets messages from a SQL database

func (SQLMessagingService) SendMessage

func (service SQLMessagingService) SendMessage(userFrom, userTo,
	text string) error

Saves a message to the SQL database

Jump to

Keyboard shortcuts

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