Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("object not found")
ErrNotFound is returned by a Persistence's Load operation when an object with the given name is not found.
Functions ¶
This section is empty.
Types ¶
type Persistence ¶
type Persistence interface { // Value creates a Value instance associated with the given name. Names should not contain file // extensions. Within the scope of a single Persistence instance, Value can be called multiple // times with the same name and all returned instances will operate on the same data in a // threadsafe manner. Value(name string) Value // Queue creates a Queue instance associated with the given name. Names should not contain file // extensions. Within the scope of a single Persistence instance, Queue can be called multiple // times with the same name and all returned instances will operate on the same data in a // threadsafe manner. Queue(name string) Queue }
Persistence provides simple support for loading and storing structures. A single Persistence instance and all of the Queue and Value instances that it returns are threadsafe. However, no such guarantee exists if multiple Persistence instances share the same backing store (e.g., the same filesystem directory).
func NewDiskPersistence ¶
func NewDiskPersistence(directory string) (Persistence, error)
NewDiskPersistence creates a diskPersistence that stores data under the given filesystem directory.
func NewMemoryPersistence ¶
func NewMemoryPersistence() Persistence
NewMemoryPersistence constructs a new Persistence that stores objects in memory.
type Queue ¶
type Queue interface { // Peek loads the object at the head of this Queue into obj. If successful, nil is returned and // obj will be populated. ErrNotFound is returned if the queue is empty or does not exist. Other // I/O errors may be returned in the event of I/O failures. Peek(obj interface{}) error // Dequeue removes the front of this Queue. If successful, nil is returned. ErrNotFound is // returned if the queue is empty or does not exist. Other I/O errors may be returned in the event // of I/O failures. If obj is non-nil, it will contain removed value upon success. Dequeue(obj interface{}) error // Enqueue stores obj at the back of this Queue. Returns nil if the object was stored, or an error // if something failed. Enqueue(obj interface{}) error }
Queue implements a simple persistent queue. Each Queue function is threadsafe and atomic within the scope of the Persistence instance that created it. However, there is no guarantee that multiple Queue function calls operate atomically. E.g., if a caller calls Peek and then later Dequeue, there's a chance that some other caller will have modified the queue in the meantime.
type Value ¶
type Value interface { // Load loads the object stored by this Value into obj. If successful, nil is returned and // obj will be populated. ErrNotFound is returned if the Value is empty or does not exist. Other // I/O errors may be returned in the event of I/O failures. Load(obj interface{}) error // Store stores obj into this Value. Returns nil if the object was stored, // or an error if something failed. Store(obj interface{}) error // Remove removes this Value from persistence. Remove returns nil if the value was removed, // ErrNotFound if the value did not exist, or some other I/O error if one occurred during removal. Remove() error }
Value stores and loads a single value.