persistence

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 8 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

func CheckStoragePermission added in v1.5.0

func CheckStoragePermission(dirBasePath string) error

CheckStoragePermission returns an error if we don't have both read and write access to a directory.

func EnsureDirectoryExists added in v1.5.0

func EnsureDirectoryExists(dirBasePath, newDirName string) error

EnsureDirectoryExists creates a new directory in a base path if it doesn't exist, returns nil if it does, and errors out if the base path doesn't exist.

func Read added in v1.5.0

func Read(filePath string) ([]byte, error)

Read a file from a file system

func Write added in v1.5.0

func Write(filePath string, data []byte) error

Write creates and writes data to a file

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

	// Snapshot takes the provided data and persists it as an unique snapshot
	// file in the provided directory appropriate for the given persistent
	// storage implementation.
	Snapshot(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