domain

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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 conflit")
	ErrBridgesNotFound       = fmt.Errorf("bridges not found")
	ErrMessageNotFound       = fmt.Errorf("message not found")
	ErrMessageAlreadyExists  = fmt.Errorf("message already exists")
	ErrAttachmentInvalid     = fmt.Errorf("invalid attachment")
	ErrAuthInvalid           = fmt.Errorf("invalid credentials")
	ErrNotImplemented        = fmt.Errorf("not implemented")
)

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	UUID        string         `json:"uuid" storm:"id"`
	Name        string         `json:"name"`
	Type        AttachmentType `json:"type"`
	MessageUUID string         `json:"message_uuid" storm:"index"`
	Data        []byte         `json:"-"`
}

func NewAttachment

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

func (*Attachment) File

func (a *Attachment) File() string

type AttachmentRepositoryPort

type AttachmentRepositoryPort interface {
	// CreateAttachment saves a new attachment.
	CreateAttachment(att *Attachment) error
	// GetAttachment returns an attachment by it's UUID.
	GetAttachment(uuid string) (*Attachment, error)
	// GetAttachmentData returns the data for an attachment.
	GetAttachmentData(att *Attachment) ([]byte, error)
	// GetAttachments returns a list of attachments for a message.
	GetAttachments(msg *Message) ([]Attachment, error)
	// GetFS returns the attachment file system
	GetAttachmentFS() fs.FS
}

type AttachmentType

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

type AuthServicePort

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

AuthServicePort handles authenticating users.

type Bridge

type Bridge struct {
	Name            string   `json:"name" mapstructure:"name"`
	Endpoints       []string `json:"endpoints" mapstructure:"endpoints"`
	OnlyText        bool     `json:"only_text" mapstructure:"only_text"`
	OnlyAttachments bool     `json:"only_attachments" mapstructure:"only_attachments"`
	Filters         []Filter `json:"filters" mapstructure:"filters"`
}

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 {
	// GetBridges returns a list of bridges that the message belongs to.
	GetBridges(msg *Message) []Bridge
}

BridgeServicePort handles finding endpoints for messages.

type Config

type Config struct {
	DB        ConfigDB         `json:"database" mapstructure:"database"`
	SMTP      ConfigSMTP       `json:"smtp" mapstructure:"smtp"`
	HTTP      ConfigHTTP       `json:"http" mapstructure:"http"`
	Bridges   []Bridge         `json:"bridges" mapstructure:"bridges"`
	Endpoints []ConfigEndpoint `json:"endpoints" mapstructure:"endpoints"`
}

func NewConfig

func NewConfig() *Config

type ConfigDB

type ConfigDB struct {
	Type        string `json:"type" mapstructure:"type"`
	DB          string `json:"db" mapstructure:"db"`
	Attachments string `json:"attachments" mapstructure:"attachments"`
}

func (*ConfigDB) IsBolt

func (db *ConfigDB) IsBolt() bool

type ConfigEndpoint

type ConfigEndpoint struct {
	Name   string            `json:"name" mapstructure:"name"`
	Type   string            `json:"type" mapstructure:"type"`
	Config map[string]string `json:"config" mapstructure:"config"`
}

type ConfigHTTP

type ConfigHTTP struct {
	Enable bool   `json:"enable" mapstructure:"enable"`
	Addr   string `json:"-" mapstructure:"-"`
	Host   string `json:"host" mapstructure:"host"`
	Port   uint16 `json:"port" mapstructure:"port"`
}

type ConfigSMTP

type ConfigSMTP struct {
	Host     string `json:"host" mapstructure:"host"`
	Port     uint16 `json:"port" mapstructure:"port"`
	PortStr  string `json:"-" mapstructure:"-"`
	Size     int    `json:"size" mapstructure:"size"`
	Auth     bool   `json:"auth" mapstructure:"auth"`
	Username string `json:"username" mapstructure:"username"`
	Password string `json:"password" mapstructure:"password"`
}

type DAO

type DAO struct {
	Attachment AttachmentRepositoryPort
	Message    MessageRepositoryPort
	Endpoint   EndpointRepositoryPort
}

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
}

EndpointPort handles sending messages to an endpoint.

type EndpointRepositoryPort

type EndpointRepositoryPort interface {
	Create(name, endpointType string, config map[string]string) error
	Get(name string) (EndpointPort, error)
}

type EndpointServicePort

type EndpointServicePort interface {
	// SendBridges sends message through the given bridges, returns error if all sends failed.
	SendBridges(msg *Message, bridges []Bridge) error
}

type Filter

type Filter struct {
	To   string `json:"to,omitempty" mapstructure:"to,omitempty"`
	From string `json:"from,omitempty" mapstructure:"from,omitempty"`
}

func (*Filter) Match

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

type Message

type Message struct {
	CreatedAt   time.Time       `json:"created_at"`      // Time message was received.
	UUID        string          `json:"uuid" storm:"id"` // UUID of the message.
	Subject     string          `json:"subject"`         // Subject of the message.
	From        string          `json:"from"`            // From is the email address of the sender.
	To          map[string]bool `json:"to"`              // To is the email addresses of the recipients.
	Text        string          `json:"text"`            // Text is the message body.
	Attachments []Attachment    `json:"-"`               // Attachment is the attachments of the message.
	Status      Status          `json:"status"`          // Status is the status of the message.
}

func NewMessage

func NewMessage(subject, from string, to map[string]bool, text string) *Message

type MessageRepositoryPort

type MessageRepositoryPort interface {
	// CreateMessage saves a new message.
	CreateMessage(msg *Message) error
	// GetMessage returns a message by it's UUID.
	GetMessage(uuid string) (*Message, error)
	// DeleteMessage deletes a message.
	DeleteMessage(msg *Message) error
	// GetMessages returns a list of messages.
	GetMessages(limit, offset int) ([]Message, error)
	// CountMessages returns the number of messages.
	CountMessages() (int, error)
	// UpdateMessage updates a message.
	UpdateMessage(msg *Message, updateFN func(msg *Message) (*Message, error)) error
}

MessageRepositoryPort handles storing messages.

type MessageServicePort

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

MessageServicePort handles creating and sending messages.

type Status

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

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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