storage

package module
v0.0.0-...-e716158 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 14 Imported by: 6

README

MailHog storage backends GoDoc Build Status

github.com/mailhog/storage implements MailHog storage backends:

  • In-memory
  • MongoDB

You should implement storage.Storage interface to provide your own storage backend.

Licence

Copyright ©‎ 2014 - 2016, Ian Kent (http://iankent.uk)

Released under MIT license, see LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemory

type InMemory struct {
	MessageIDIndex map[string]int
	Messages       []*data.Message
	// contains filtered or unexported fields
}

InMemory is an in memory storage backend

func CreateInMemory

func CreateInMemory() *InMemory

CreateInMemory creates a new in memory storage backend

func (*InMemory) Count

func (memory *InMemory) Count() int

Count returns the number of stored messages

func (*InMemory) DeleteAll

func (memory *InMemory) DeleteAll() error

DeleteAll deletes all in memory messages

func (*InMemory) DeleteOne

func (memory *InMemory) DeleteOne(id string) error

DeleteOne deletes an individual message by storage ID

func (*InMemory) List

func (memory *InMemory) List(start int, limit int) (*data.Messages, error)

List lists stored messages by index

func (*InMemory) Load

func (memory *InMemory) Load(id string) (*data.Message, error)

Load returns an individual message by storage ID

func (*InMemory) Search

func (memory *InMemory) Search(kind, query string, start, limit int) (*data.Messages, int, error)

Search finds messages matching the query

func (*InMemory) Store

func (memory *InMemory) Store(m *data.Message) (string, error)

Store stores a message and returns its storage ID

type Maildir

type Maildir struct {
	Path string
}

Maildir is a maildir storage backend

func CreateMaildir

func CreateMaildir(path string) *Maildir

CreateMaildir creates a new maildir storage backend

func (*Maildir) Count

func (maildir *Maildir) Count() int

Count returns the number of stored messages

func (*Maildir) DeleteAll

func (maildir *Maildir) DeleteAll() error

DeleteAll deletes all in memory messages

func (*Maildir) DeleteOne

func (maildir *Maildir) DeleteOne(id string) error

DeleteOne deletes an individual message by storage ID

func (*Maildir) List

func (maildir *Maildir) List(start, limit int) (*data.Messages, error)

List lists stored messages by index

func (*Maildir) Load

func (maildir *Maildir) Load(id string) (*data.Message, error)

Load returns an individual message by storage ID

func (*Maildir) Search

func (maildir *Maildir) Search(kind, query string, start, limit int) (*data.Messages, int, error)

Search finds messages matching the query

func (*Maildir) Store

func (maildir *Maildir) Store(m *data.Message) (string, error)

Store stores a message and returns its storage ID

type MongoDB

type MongoDB struct {
	Client     *mongo.Client
	Collection *mongo.Collection
}

MongoDB represents MongoDB backed storage backend

func CreateMongoDB

func CreateMongoDB(uri, db, coll string) *MongoDB

CreateMongoDB creates a MongoDB backed storage backend

func (*MongoDB) Count

func (mongo *MongoDB) Count() int

Count returns the number of stored messages

func (*MongoDB) DeleteAll

func (mongo *MongoDB) DeleteAll() error

DeleteAll deletes all messages stored in MongoDB

func (*MongoDB) DeleteOne

func (mongo *MongoDB) DeleteOne(id string) error

DeleteOne deletes an individual message by storage ID

func (*MongoDB) List

func (mongo *MongoDB) List(start int, limit int) (*data.Messages, error)

List returns a list of messages by index

func (*MongoDB) Load

func (mongo *MongoDB) Load(id string) (*data.Message, error)

Load loads an individual message by storage ID

func (*MongoDB) Search

func (mongo *MongoDB) Search(kind, query string, start, limit int) (*data.Messages, int, error)

Search finds messages matching the query

func (*MongoDB) Store

func (mongo *MongoDB) Store(m *data.Message) (string, error)

Store stores a message in MongoDB and returns its storage ID

type Storage

type Storage interface {
	Store(m *data.Message) (string, error)
	List(start, limit int) (*data.Messages, error)
	Search(kind, query string, start, limit int) (*data.Messages, int, error)
	Count() int
	DeleteOne(id string) error
	DeleteAll() error
	Load(id string) (*data.Message, error)
}

Storage represents a storage backend

Jump to

Keyboard shortcuts

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