core

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAttachmentInvalid  = fmt.Errorf("invalid attachment")
	ErrAttachmentNotFound = fmt.Errorf("attachment not found")
)
View Source
var (
	ErrEndpointSendFailed    = fmt.Errorf("endpoint send failed")
	ErrEndpointInvalidType   = fmt.Errorf("invalid endpoint type")
	ErrEndpointInvalidConfig = fmt.Errorf("invalid endpoint config")
	ErrEndpointNotFound      = fmt.Errorf("endpoint not found")
	ErrEndpointNameConflict  = fmt.Errorf("endpoint name conflict")
)
View Source
var (
	ErrMessageNotFound      = fmt.Errorf("message not found")
	ErrMessageAlreadyExists = fmt.Errorf("message already exists")
)
View Source
var ErrAuthInvalid = fmt.Errorf("invalid credentials")
View Source
var ErrBridgesNotFound = fmt.Errorf("bridges not found")
View Source
var ErrNotImplemented = errors.New("not implemented")

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	UUID        string
	Name        string
	Type        AttachmentType
	MessageUUID string
	Data        []byte
}

func (*Attachment) File

func (a *Attachment) File() string

type AttachmentRepositoryPort

type AttachmentRepositoryPort interface {
	// Create saves a new attachment.
	Create(att *Attachment) error
	// Get returns an attachment by it's UUID without data.
	Get(uuid string) (*Attachment, error)
	// GetData returns the data for an attachment.
	GetData(att *Attachment) ([]byte, error)
	// GetFS returns the attachment file system.
	GetFS() fs.FS
	// ListByMessage returns a list of attachments for a message without data.
	ListByMessage(msg *Message) ([]Attachment, error)
	// DeleteData deletes the data for an attachment.
	DeleteData(att *Attachment) error
}

type AttachmentType

type AttachmentType string
const (
	TypePNG  AttachmentType = "png"
	TypeJPEG AttachmentType = "jpeg"
)

func AttachmentDataValid

func AttachmentDataValid(data []byte) (AttachmentType, error)

AttachmentDataValid returns the type of the attachment data.

type AuthServicePort

type AuthServicePort interface {
	AnonymousLogin() bool
	Login(username, password string) error
}

type Bridge

type Bridge struct {
	Name            string
	Endpoints       []string
	OnlyText        bool
	OnlyAttachments bool
	Filters         []Filter
}

func NewBridge

func NewBridge(name string, endpoints []string, onlyText, onlyAttachments bool, filters []Filter) *Bridge

func (*Bridge) EndpointMessage

func (b *Bridge) EndpointMessage(msg *Message) *EndpointMessage

func (*Bridge) Match

func (b *Bridge) Match(msg *Message) bool

type BridgeServicePort

type BridgeServicePort interface {
	// ListByMessage returns bridges that the message belongs to.
	ListByMessage(msg *Message) []*Bridge
}

type Database

type Database interface {
	Close() error
	AttachmentRepository() AttachmentRepositoryPort
	MessageRepository() MessageRepositoryPort
}

type EndpointAttachment

type EndpointAttachment struct {
	Name string
	Type AttachmentType
	Data []byte
}

func NewEndpointAttachments

func NewEndpointAttachments(atts []Attachment) []EndpointAttachment

type EndpointMessage

type EndpointMessage struct {
	Text        string               // Text is the message body.
	Attachments []EndpointAttachment // Attachments is a list of attachments.
}

func (*EndpointMessage) IsEmpty

func (em *EndpointMessage) IsEmpty() bool

type EndpointPort

type EndpointPort interface {
	// Send sends the message to the endpoint.
	Send(msg *EndpointMessage) error
}

type EndpointRepositoryPort

type EndpointRepositoryPort interface {
	// Create initializes a new endpoint.
	Create(name, endpointType string, config map[string]string) error
	// Get returns an endpoint by it's name.
	Get(name string) (EndpointPort, error)
}

type EndpointServicePort

type EndpointServicePort interface {
	SendByEndpointNames(emsg *EndpointMessage, endpointNames []string) error
}

type Filter

type Filter struct {
	To   string
	From string
	// contains filtered or unexported fields
}

func NewFilter

func NewFilter(to, from, toRegex, fromRegex string) Filter

func (*Filter) Match

func (f *Filter) Match(msg *Message) bool

type Message

type Message struct {
	UUID        string              // UUID of the message.
	From        string              // From is the email address of the sender.
	To          map[string]struct{} // To is the email addresses of the recipients.
	Subject     string              // Subject of the message.
	Text        string              // Text is the message body.
	Attachments []Attachment        // Attachment is the attachments of the message.
	Status      Status              // Status is the status of the message.
	CreatedAt   time.Time           // Time message was received.
}

func NewMessage

func NewMessage(subject, from string, to map[string]struct{}, text string) *Message

func (*Message) NewAttachment

func (m *Message) NewAttachment(name string, data []byte) (*Attachment, error)

type MessageRepositoryPort

type MessageRepositoryPort interface {
	// Create saves a message.
	Create(msg *Message) error
	// Count returns the number of messages.
	Count() (int, error)
	// Get returns a message by it's UUID.
	Get(uuid string) (*Message, error)
	// List messages.
	List(limit, offset int) ([]Message, error)
	// Update a message.
	Update(msg *Message, updateFN func(msg *Message) (*Message, error)) error
	// Delete a message.
	Delete(msg *Message) error
}

type MessageServicePort

type MessageServicePort interface {
	// Create a new message and saves it.
	Create(subject, from string, to map[string]struct{}, text string) (*Message, error)
	// CreateAttachment adds an attachment to a message and saves it.
	CreateAttachment(msg *Message, name string, data []byte) (*Attachment, error)
	// Get a message with attachments.
	Get(uuid string) (*Message, error)
	// List messages with attachments.
	List(limit, offset int) ([]Message, error)
	// Process handles sending message to bridge's endpoints.
	Process(msg *Message, bridges []*Bridge) error
	// UpdateStatus updates the status of a message.
	UpdateStatus(msg *Message, status Status) error
}

type Status

type Status uint8
const (
	StatusCreated Status = iota
	StatusSent
	StatusFailed
	StatusSkipped
)

Jump to

Keyboard shortcuts

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