data

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package data contains basic threadsafe data structures with filesystem persistance and configurable flushing policies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlushPolicy

type FlushPolicy int

FlushPolicy is the type of flush policy to use.

const (
	// FlushOnEdit saves the object to disk after every modification.
	FlushOnEdit FlushPolicy = iota
	// FlushExplicit saves the object to disk only if the Flush method of
	// the object is explicitly called.
	FlushExplicit
	// FlushNone never saves the object to disk.
	FlushNone
)

type UnsortedKV

type UnsortedKV struct {
	sync.Mutex
	// contains filtered or unexported fields
}

UnsortedKV is a thread safe and unsorted key-value storage with optional persistency on disk.

func NewDiskUnsortedKV added in v1.8.0

func NewDiskUnsortedKV(fileName string) (*UnsortedKV, error)

NewDiskUnsortedKV returns an UnsortedKV that flushed data on disk every time it gets updated.

func NewDiskUnsortedKVReader added in v1.8.0

func NewDiskUnsortedKVReader(fileName string) (*UnsortedKV, error)

NewDiskUnsortedKVReader returns an UnsortedKV from disk as a reader but it doesn't flush any modifications on disk.

func NewMemUnsortedKV added in v1.8.0

func NewMemUnsortedKV() (*UnsortedKV, error)

NewMemUnsortedKV returns an UnsortedKV that only lives in memory and never persists on disk.

func NewUnsortedKV

func NewUnsortedKV(fileName string, flushPolicy FlushPolicy) (*UnsortedKV, error)

NewUnsortedKV creates a new UnsortedKV with the given flush policy. If fileName already exists, it will be deserialized and loaded.

func (*UnsortedKV) Clear

func (u *UnsortedKV) Clear() error

Clear deletes every named object from the store.

func (*UnsortedKV) Del

func (u *UnsortedKV) Del(name string) error

Del deletes a named object from the store.

func (*UnsortedKV) Each

func (u *UnsortedKV) Each(cb func(k, v string) bool)

Each iterates each named object in the store by executing the callback cb on them, if the callback returns true the iteration is interrupted.

func (*UnsortedKV) Empty added in v1.8.0

func (u *UnsortedKV) Empty() bool

Empty returns bool if the store is empty.

func (*UnsortedKV) Flush

func (u *UnsortedKV) Flush() error

Flush flushes the store to disk if the flush policy is different than FlushNone

func (*UnsortedKV) Get

func (u *UnsortedKV) Get(name string) (v string, found bool)

Get return the value of the named object if present, or returns found as false otherwise.

func (*UnsortedKV) GetOr

func (u *UnsortedKV) GetOr(name, or string) string

GetOr will return the value of the named object if present, or a default value.

func (*UnsortedKV) Has

func (u *UnsortedKV) Has(name string) bool

Has return true if name exists in the store.

func (*UnsortedKV) MarshalJSON added in v1.8.0

func (u *UnsortedKV) MarshalJSON() ([]byte, error)

MarshalJSON is used to serialize the UnsortedKV data structure to JSON correctly.

func (*UnsortedKV) Set

func (u *UnsortedKV) Set(name, value string) error

Set sets a value for a named object.

Jump to

Keyboard shortcuts

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