persistence

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: MIT Imports: 6 Imported by: 16

Documentation

Overview

Package persistence adds a layer which handles data storage. This package separates the data from the business layer and is responsible for saving and retrieving it.

Index

Constants

View Source
const KeyLength = encryption.KeyLength

KeyLength represents the byte size of the key.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataDescriptor

type DataDescriptor interface {
	Name() string
	Directory() string
	Content() ([]byte, error)
}

DataDescriptor is an interface representing data saved in the persistence layer represented by Handle.

type Handle

type Handle interface {

	// Save takes the provided data and persists it under the given name in the
	// provided directory appropriate for the given persistent storage
	// implementation.
	Save(data []byte, directory string, name string) error

	// ReadAll returns all non-archived data. It returns two channels: the first
	// channel returned is a non-buffered channel streaming DataDescriptors of
	// all data read. The second channel is a non-buffered channel streaming all
	// errors occurred during reading. Returned channels can be integrated
	// in a pipeline pattern. The function is non-blocking. Channels are closed
	// when there is no more to be read.
	ReadAll() (<-chan DataDescriptor, <-chan error)

	// Archive marks the entire directory with the name provided as archived
	// so that the data in that directory is not returned from ReadAll.
	Archive(directory string) error
}

Handle is an interface for data persistence. Underlying implementation can write data e.g. to disk, cache, or hardware module.

func NewDiskHandle

func NewDiskHandle(path string) (Handle, error)

NewDiskHandle creates on-disk data persistence handle

func NewEncryptedPersistence

func NewEncryptedPersistence(handle Handle, password string) Handle

NewEncryptedPersistence creates an adapter for the disk persistence to store data in an encrypted format

Jump to

Keyboard shortcuts

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