gobpersist

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// RetrySaveInterval is the delay between save attempts if the previous one failed.
	RetrySaveInterval = 2 * time.Second
)

Variables

View Source
var (
	// ErrorNoFilename is returned when trying to save without specifying a file
	ErrorNoFilename = errors.New("Filename not specified")
)

Functions

This section is empty.

Types

type GobPersist

type GobPersist struct {
	sync.Mutex

	// Filename is the name of the file to use to persist the information
	Filename string
	// Target needs to be set to a pointer to the structure or field that is to be persisted
	Target interface{}
	// SaveInterval is the minimum interval between conditional saves.
	SaveInterval time.Duration
	// contains filtered or unexported fields
}

GobPersist is a simple helper package that allows saving and loading a target to a file using gob. It also handles timed saves

func (*GobPersist) Load

func (g *GobPersist) Load() error

Load will try to restore the structure Target points to.

func (*GobPersist) Save

func (g *GobPersist) Save() error

Save will write the Target to file, regardless if it was changed or how long ago the previous save was.

func (*GobPersist) SaveConditional

func (g *GobPersist) SaveConditional(modified bool) error

SaveConditional performs a save operation if the Target is modified and the minimum 'SaveInterval' has passed. If modified is true, Touch is called internally.

func (*GobPersist) Touch

func (g *GobPersist) Touch()

Touch signals that the Target has been changed and should be called after modifications

Jump to

Keyboard shortcuts

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