Documentation ¶
Overview ¶
Package dump manages a list of items in memory with concurrency-safe functions for accessing and manipulating them.
Index ¶
- Constants
- Variables
- type Dump
- func (d *Dump) Add(item Item) (int, error)
- func (d *Dump) Load() error
- func (d *Dump) Map(f func(item Item) error) error
- func (d *Dump) MarshalJSON() ([]byte, error)
- func (d *Dump) Save() error
- func (d *Dump) Update(f func(items []Item) error) error
- func (d *Dump) View(f func(items []Item) error) error
- type Item
- type Type
Constants ¶
const ( // PERSIST_MANUAL is the default disk-persistence setting. The user has to // manually save the dump to disk using the Save() function. PERSIST_MANUAL = iota // PERSIST_WRITES is a disk-persistence setting that will save the dump // to disk when either Add() or Update() is called. PERSIST_WRITES // PERSIST_INTERVAL is a disk-persistence setting that will save the dump // on a set interval (currently once every 60 seconds). PERSIST_INTERVAL )
Variables ¶
var ( // ErrInvalidPersist is thrown when an invalid disk-persistence setting is // provided when calling NewDump(). ErrInvalidPersist = errors.New("invalid persist type") // ErrInvalidTypes is thrown when no types are listed when calling // NewDump(). Without type definitions it is impossible to persist on disk // without possible data loss. ErrInvalidTypes = errors.New("no types were provided") // ErrInvalidFilename is thrown when NewDump() is called with an empty // filename - making persistence impossible. ErrInvalidFilename = errors.New("invalid filename") )
Functions ¶
This section is empty.
Types ¶
type Dump ¶
type Dump struct {
// contains filtered or unexported fields
}
Dump represents a collection of items that persist on disk.
func NewDump ¶
NewDump is the primary constructor function for creating dumps. The provided filename is where the dump will persist to disk (and read from disk). The persist int is one of the dump.PERSIST_ constants. The provided types register the types that will be held in the dump.
NewDump will return an error if the persist parameter is not a valid dump.PERSIST_ constant.
func (*Dump) Add ¶
Add appends an Item on the end of the dump. It returns the id of the item and an error if there was a problem persisting the dump on the disk (if PERSIST_WRITE is enabled).
func (*Dump) Load ¶
Load reads the dump from disk using the filename provided when NewDump() was called.
func (*Dump) Map ¶
Map applies the function f to each item in the dump. It returns an error if f returns an error for one of the items. If PERSIST_WRITES is enabled Map might also return an error if there is an error saving the dump to disk.
func (*Dump) MarshalJSON ¶
MarshalJSON returns the dump as a JSON list. It returns an error if there was an error marshaling one of the items.
func (*Dump) Save ¶
Save persists the dump on disk using the filename provided when NewDump() was called.
type Item ¶
Item implements the json.Marshaler interface and is used so that the dump itself can implement the json.Marshaler function by aggregating all items.
type Type ¶
type Type struct { // Name is the name of this type. Usually it takes the form of // "package.Name" -- so for a struct User{} in package main this field // would be "main.User". Name string // Value is an empty struct of this type. For a struct User{}, this would // be User{}. Value interface{} }
Type is used to register types from outside packages so that they are recognized when loading or saving the dump.