app

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	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")
	ErrAttachmentInvalid     = fmt.Errorf("invalid attachment")
)

Functions

This section is empty.

Types

type Attachment

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

func NewAttachment

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

type AttachmentType

type AttachmentType uint
const (
	TypePNG AttachmentType = iota
	TypeJPEG
)

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"`
	EmailFrom       string   `json:"email_from" mapstructure:"email_from"`
	EmailTo         string   `json:"email_to" mapstructure:"email_to"`
	OnlyText        bool     `json:"only_text" mapstructure:"only_text"`
	OnlyAttachments bool     `json:"only_attachments" mapstructure:"only_attachments"`
}

func (*Bridge) EndpointMessage added in v0.1.0

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 {
	ConfigSMTP      ConfigSMTP       `json:"smtp" mapstructure:"smtp"`
	Bridges         []Bridge         `json:"bridges" mapstructure:"bridges"`
	ConfigEndpoints []ConfigEndpoint `json:"endpoints" mapstructure:"endpoints"`
}

func NewConfig

func NewConfig() *Config

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 ConfigSMTP added in v0.2.0

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"`
}

type EndpointMessage added in v0.1.0

type EndpointMessage struct {
	Text        string        `json:"text"`        // Text is the message body.
	Attachments []*Attachment `json:"attachments"` // Attachments is a list of attachments.
}

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 added in v0.2.0

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

type Message

type Message struct {
	Time        time.Time       `json:"time"`        // Time message was received.
	UUID        string          `json:"uuid"`        // 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:"attachments"` // Attachments is a list of attachments.
}

func NewMessage

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

type MessageRepositoryPort

type MessageRepositoryPort interface {
	// Create saves the message.
	Create(msg *Message) error
	// Update updates the message.
	Update(msg *Message) 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)
	// AddAttachment adds an attachment to a message.
	AddAttachment(msg *Message, name string, data []byte) error
	// Send finds endpoints for the message and sends to it.
	Send(msg *Message) error
}

MessageServicePort handles creating and sending messages.

Jump to

Keyboard shortcuts

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