storage

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MIT Imports: 10 Imported by: 3

README

MailHog storage backends GoDoc Build Status

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

  • In-memory
  • MongoDB
  • Directory
  • MultiUserDirectory

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

	MessagesLimit int
	// 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(room string) int

Count returns the number of stored messages

func (*InMemory) DeleteAll

func (memory *InMemory) DeleteAll(room string) error

DeleteAll deletes all in memory messages

func (*InMemory) DeleteOne

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

DeleteOne deletes an individual message by storage ID

func (*InMemory) List

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

List lists stored messages by index

func (*InMemory) Load

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

Load returns an individual message by storage ID

func (*InMemory) Search

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

Search finds messages matching the query

func (*InMemory) Store

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

Store stores a message and returns its storage ID

type Maildir

type Maildir struct {
	Path          string
	MessagesLimit int
}

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(room string) int

Count returns the number of stored messages

func (*Maildir) DeleteAll

func (maildir *Maildir) DeleteAll(room string) error

DeleteAll deletes all in memory messages

func (*Maildir) DeleteOne

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

DeleteOne deletes an individual message by storage ID

func (*Maildir) List

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

List lists stored messages by index

func (*Maildir) Load

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

Load returns an individual message by storage ID

func (*Maildir) Search

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

Search finds messages matching the query

func (*Maildir) Store

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

Store stores a message and returns its storage ID

type MongoDB

type MongoDB struct {
	Session    *mgo.Session
	Collection *mgo.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(room string) int

Count returns the number of stored messages

func (*MongoDB) DeleteAll

func (mongo *MongoDB) DeleteAll(room string) error

DeleteAll deletes all messages stored in MongoDB

func (*MongoDB) DeleteOne

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

DeleteOne deletes an individual message by storage ID

func (*MongoDB) List

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

List returns a list of messages by index

func (*MongoDB) Load

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

Load loads an individual message by storage ID

func (*MongoDB) Search

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

Search finds messages matching the query

func (*MongoDB) Store

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

Store stores a message in MongoDB and returns its storage ID

type Storage

type Storage interface {
	Store(room string, m *data.Message) (string, error)
	List(room string, start, limit int) (*data.Messages, error)
	Search(room string, kind, query string, start, limit int) (*data.Messages, int, error)
	Count(room string) int
	DeleteOne(room string, id string) error
	DeleteAll(room string) error
	Load(room string, 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