datasafe

package
v0.0.0-...-1e2c71d Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package datasafe contains all currently implemented DataSafes.

Index

Constants

View Source
const FileMemoryName = "FileMemory"

FileMemoryName contains the name of the DataSafe

Variables

View Source
var ErrFileMemoryInvalidID = errors.New("filememory got invalid ID")

ErrFileMemoryInvalidID is an error which is returned if ID is invalid

View Source
var ErrFileMemoryNotActive = errors.New("filememory was not activated")

ErrFileMemoryNotActive is an error which is returned if fileMemory is used without initialising

Functions

This section is empty.

Types

type FileMemory

type FileMemory struct {
	// Interval in minutes when a cleanup operation is started.
	// A cleanup operation will reduce memory if MaximumMemory is exceeded by saving polls to disk.
	ClearInterval int

	// Ratio of 'free' memory versus used memory.
	// Example: if set to 0.75 and Maximum memory is set to 100, then 75 polls will be kept in memory after cleanup.
	ClearAfterRatio float64

	// Number of polls needed in memory before cleanup is performed.
	MaximumMemory int

	// Interval in minutes in which all polls in memory will be synced to disk.
	// This is used to reduce damage if something goes horribly wrong.
	// Setting this to 0 disables syncing to disk.
	DiscSyncInterval int

	//  Path where polls are saved to disk.
	Path string
	// contains filtered or unexported fields
}

FileMemory holds a number of polls in memory and saves all other to disk.

func (*FileMemory) DeleteAnswer

func (fm *FileMemory) DeleteAnswer(pollID, answerID string) error

DeleteAnswer deletes a single answer identified by ID.

func (*FileMemory) FlushAndClose

func (fm *FileMemory) FlushAndClose()

FlushAndClose saves all poll to disk. It is only guarateed that the data is saved to disk if this function is called.

func (*FileMemory) GetChange

func (fm *FileMemory) GetChange(pollID, answerID string) (string, error)

GetChange returns the password needed for changing an answer.

func (*FileMemory) GetPollConfig

func (fm *FileMemory) GetPollConfig(pollID string) ([]byte, error)

GetPollConfig returns the poll configuration.

func (*FileMemory) GetPollCreator

func (fm *FileMemory) GetPollCreator(pollID string) (string, error)

GetPollCreator returns the poll creator.

func (*FileMemory) GetPollResult

func (fm *FileMemory) GetPollResult(pollID string) ([][]int, []string, []string, []string, error)

GetPollResult returns the results of a poll.

func (*FileMemory) GetSinglePollResult

func (fm *FileMemory) GetSinglePollResult(pollID, answerID string) ([]int, string, string, error)

GetSinglePollResult returns a single results of a poll identified by ID.

func (*FileMemory) LoadConfig

func (fm *FileMemory) LoadConfig(data []byte) error

LoadConfig loads the configuration of the FileMemory from JSON encoded data.

func (*FileMemory) MarkPollDeleted

func (fm *FileMemory) MarkPollDeleted(pollID string) error

MarkPollDeleted marks a poll as deleted. It is not deleted imidiately, but on next garbage collect.

func (*FileMemory) OverwritePollResult

func (fm *FileMemory) OverwritePollResult(pollID, answerID, name, comment string, results []int, change string) error

OverwritePollResult overwrites the results of a single poll with a given new result. Errors out if the answerID is unknown

func (*FileMemory) RunGC

func (fm *FileMemory) RunGC() error

RunGC runs the garbage collection and removes deleted polls.

func (*FileMemory) SavePollConfig

func (fm *FileMemory) SavePollConfig(pollID string, config []byte) error

SavePollConfig saves the poll configuration.

func (*FileMemory) SavePollCreator

func (fm *FileMemory) SavePollCreator(pollID, name string) error

SavePollCreator sets the poll creator.

func (*FileMemory) SavePollResult

func (fm *FileMemory) SavePollResult(pollID, name, comment string, results []int, change string) (string, error)

SavePollResult saves the results of a single poll.

type FileMemoryPollResult

type FileMemoryPollResult struct {
	Data          [][]int
	Names         []string
	Comments      []string
	Config        []byte
	LastAccess    time.Time
	Deleted       bool
	Creator       string
	Change        []string
	IDs           []string
	AnswerCounter int
}

FileMemoryPollResult is a helper struct which holds the Results of a poll. The data is only guaranteed to be saved to disk after FlushAndClose is called.

Jump to

Keyboard shortcuts

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