data

package
v0.0.0-...-dee8dd0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2017 License: ISC Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateID is returned by InsertMessage when the a message with the
	// specified ID already exists in the folder.
	ErrDuplicateID = errors.New("duplicate ID")

	// ErrInvalidID is returned when an invalid id is provided.
	ErrInvalidID = errors.New("invalid ID")

	// ErrNotFound is returned when a record matching the query or no record at
	// all is found in the database.
	ErrNotFound = errors.New("record not found")
)

Functions

This section is empty.

Types

type Folder

type Folder interface {
	// InsertNewMessage inserts a new message with the specified suffix and
	// id into the folder and returns the ID. For normal folders, suffix
	// could be the encoding type. For special use folders like "Pending",
	// suffix could be used as a 'key', like a reason code (why the message is
	// marked as Pending).
	InsertNewMessage(msg []byte, suffix uint64) (uint64, error)

	// InsertMessage inserts a new message with the specified suffix and id
	// into the folder and returns the ID. If input id is 0 or >= NextID,
	// ErrInvalidID is returned.
	InsertMessage(id uint64, msg []byte, suffix uint64) error

	// GetMessage retrieves a message from the folder by its index. It returns the
	// suffix and the message. An error is returned if the message with the given
	// index doesn't exist in the database.
	GetMessage(id uint64) (uint64, []byte, error)

	// DeleteMessage deletes a message with the given index from the store. An error
	// is returned if the message doesn't exist in the store.
	DeleteMessage(id uint64) error

	// ForEachMessage runs the given function for messages that have IDs between
	// lowID and highID with the given suffix. If lowID is 0, it starts from the
	// first message. If highID is 0, it returns all messages with id >= lowID with
	// the given suffix. If suffix is zero, it returns all messages between lowID
	// and highID, irrespective of the suffix. Note that any combination of lowID,
	// highID and suffix can be zero for the desired results. Both lowID and highID
	// are inclusive.
	//
	// Suffix is useful for getting all messages of a particular type. For example,
	// retrieving all messages with encoding type 2.
	//
	// The function terminates early if an error occurs and iterates in the
	// increasing order of index. Make sure it doesn't take long to execute. DO NOT
	// execute any other database operations in it.
	ForEachMessage(lowID, highID, suffix uint64,
		fn func(id, suffix uint64, msg []byte) error) error

	// NextID returns the next index value that will be assigned in the mailbox..
	NextID() uint64

	// LastID returns the highest index value in the mailbox, followed by a
	// map containing the last indices for each suffix.
	LastID() (uint64, map[uint64]uint64)
}

Folder represents a store of data indexed by an id number.

type Folders

type Folders interface {
	New(string) (Folder, error)
	Get(string) (Folder, error)
	Rename(string, string) error
	Names() []string
	Delete(string) error
}

Folders represents a set of named folders.

func NewMemFolders

func NewMemFolders() Folders

NewMemFolders returns an in-memory folders object.

Jump to

Keyboard shortcuts

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