archive

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound means a mail could not be found in the Store.
	ErrNotFound = errors.New("mail not found")
)

Functions

func MailIDFromContext added in v0.13.4

func MailIDFromContext(ctx context.Context) uuid.UUID

MailIDFromContext returns the mail UUID from the given Context, or uuid.Nil if the Context has no mail UUID.

func New

func New(s Store, opts ...Option) postdog.Plugin

New creates the archive plugin.

func WithMailID added in v0.13.4

func WithMailID(ctx context.Context, id uuid.UUID) context.Context

WithMailID returns a new Context that carries the given UUID. Mails that are archived with that Context will use that UUID as their UUID when stored in a database.

Types

type Cursor

type Cursor interface {
	// Next advances the cursor to the next Mail.
	// Implementations should return true if the next call to Current() would
	// return a valid Mail, or false if the Cursor reached the end or if Next()
	// failed because of an error. In the latter case, Err() should return that error.
	Next(stdctx.Context) bool

	// Current returns the current Mail.
	Current() Mail

	// All returns the remaining Mails from the Cursor and calls cur.Close(ctx) afterwards.
	All(stdctx.Context) ([]Mail, error)

	// Err returns the current error that occurred during a previous Next() call.
	Err() error

	// Close closes the Cursor. Users must call Close() after using the Cursor if they don't call All().
	Close(stdctx.Context) error
}

Cursor is a cursor archived Mails.

type Mail

type Mail struct {
	letter.Letter
	// contains filtered or unexported fields
}

Mail is the archived form of a sent mail, containing the send time and send error of the mail.

func ExpandMail

func ExpandMail(pm postdog.Mail) Mail

ExpandMail takes a postdog.Mail and builds a Mail from it. If pm has a SendError() method, the error will be added to the Mail. If pm has a SentAt() method, the time will be added as the send time.

func (Mail) ID

func (m Mail) ID() uuid.UUID

ID returns the mail's ID.

func (Mail) Map

func (m Mail) Map(opts ...mapper.Option) map[string]interface{}

Map maps m to a map[string]interface{}.

func (*Mail) Parse

func (m *Mail) Parse(mm map[string]interface{})

Parse parses mm into m.

func (Mail) SendError

func (m Mail) SendError() string

SendError returns the message of the send error. An empty string means there was no error.

func (Mail) SentAt

func (m Mail) SentAt() time.Time

SentAt returns the time at which the mail was sent.

func (Mail) WithID

func (m Mail) WithID(id uuid.UUID) Mail

WithID returns a copy of m with it's ID set to id.

func (Mail) WithSendError

func (m Mail) WithSendError(err string) Mail

WithSendError returns a copy of m with it's send error set to err.

func (Mail) WithSendTime

func (m Mail) WithSendTime(t time.Time) Mail

WithSendTime returns a copy of m with it's send time set to t.

type Option

type Option func(*config)

Option is an archive option.

func InsertTimeout added in v0.10.2

func InsertTimeout(d time.Duration) Option

InsertTimeout returns an Option that sets the timeout for inserts.

func WithLogger

func WithLogger(l Printer) Option

WithLogger returns an Option that sets the error logger.

type Printer

type Printer interface {
	Print(...interface{})
}

Printer is the logger interface.

type Store

type Store interface {
	// Insert inserts a Mail into the Store.
	Insert(stdctx.Context, Mail) error

	// Find returns the Mail with the given ID.
	Find(stdctx.Context, uuid.UUID) (Mail, error)

	// Query queries the Store using the given query.Query.
	Query(stdctx.Context, query.Query) (Cursor, error)

	// Remove removes the given Mail from the Store.
	Remove(stdctx.Context, Mail) error
}

Store is the underlying store for the Mails.

Directories

Path Synopsis
Package mock_archive is a generated GoMock package.
Package mock_archive is a generated GoMock package.

Jump to

Keyboard shortcuts

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