app

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEndpointType   = fmt.Errorf("invalid endpoint type")
	ErrInvalidEndpointConfig = fmt.Errorf("invalid endpoint config")
	ErrNoEndpoints           = fmt.Errorf("no endpoints")
	ErrMessageNotFound       = fmt.Errorf("message not found")
	ErrInvalidAttachment     = 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"`
	Filters   []Filter `json:"filters" mapstructure:"filters"`
	Endpoints []string `json:"endpoints" mapstructure:"endpoints"`
}

func (*Bridge) Match

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

type BridgeServicePort

type BridgeServicePort interface {
	GetEndpoints(msg *Message) []EndpointPort
}

BridgeServicePort handles finding endpoints for messages.

type Config

type Config struct {
	Port            string           `json:"port" mapstructure:"port"`
	Bridges         []Bridge         `json:"bridges" mapstructure:"bridges"`
	ConfigEndpoints []ConfigEndpoint `json:"endpoints" mapstructure:"endpoints"`
}

func NewConfig

func NewConfig() *Config

func (*Config) NewEndpoints

func (c *Config) NewEndpoints(factory func(senderType string, config map[string]string) (EndpointPort, error)) map[string]EndpointPort

NewEndpoints creates a name to Endpoint map using a factory.

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 EndpointPort

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

EndpointPort handles sending messages to an endpoint.

type Filter

type Filter struct {
	To        string `json:"to,omitempty" mapstructure:"to,omitempty"`
	ToRegex   bool   `json:"to_regex,omitempty" mapstructure:"to_regex,omitempty"`
	From      string `json:"from,omitempty" mapstructure:"from,omitempty"`
	FromRegex bool   `json:"from_regex,omitempty" mapstructure:"from_regex,omitempty"`
}

func (*Filter) Match

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

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