blasphem/pkg/storage/fs.go

56 lines
1.4 KiB
Go
Raw Normal View History

2022-11-13 10:03:13 -05:00
package storage
import (
"errors"
"sync"
)
var (
ErrNoSuchKey = errors.New("no such key in store")
2022-11-13 11:55:10 -05:00
ErrKeyExists = errors.New("key already exists")
2022-11-13 10:03:13 -05:00
)
2022-11-13 11:55:10 -05:00
// Item is an item in a datastore.
2022-11-13 10:03:13 -05:00
type Item interface {
2022-11-13 11:55:10 -05:00
// Item is lockable if updating data item directly.
2022-11-13 10:03:13 -05:00
sync.Locker
2022-11-13 11:55:10 -05:00
// Dirty sets the dirty flag for the item so it will be flushed.
2022-11-13 10:03:13 -05:00
Dirty()
2022-11-13 11:55:10 -05:00
// IsDirty gets the dirty flag for the item.
2022-11-13 10:03:13 -05:00
IsDirty() bool
2022-11-13 11:55:10 -05:00
// GetData gets the data for the item.
2022-11-13 10:03:13 -05:00
GetData() interface{}
2022-11-13 11:55:10 -05:00
// GetData sets the data for the item.
2022-11-13 10:03:13 -05:00
SetData(interface{})
2022-11-13 11:55:10 -05:00
// ItemKey gets the key of the item.
2022-11-13 10:03:13 -05:00
ItemKey() string
}
2022-11-13 11:55:10 -05:00
// Store represents a datastore.
2022-11-13 10:03:13 -05:00
type Store interface {
2022-11-13 11:55:10 -05:00
// GetItem loads the specified key from the store into data and returns the Item.
// If err is ErrKeyExists, Item will be the existing item.
2022-11-13 10:03:13 -05:00
GetItem(key string, data interface{}) (Item, error)
2022-11-13 11:55:10 -05:00
// Get is the same as GetItem, but only returns error.
2022-11-13 10:03:13 -05:00
Get(key string, data interface{}) error
2022-11-13 11:55:10 -05:00
// Put puts the specified key into the store. If the key already exists, it clobbers.
// Note that any existing items will then dangle.
2022-11-13 10:03:13 -05:00
Put(key string, version, minorVersion int, secretMode bool, data interface{}) (Item, error)
2022-11-13 11:55:10 -05:00
// FlushAll flushes the store to backing.
2022-11-13 10:03:13 -05:00
FlushAll() []error
2022-11-13 11:55:10 -05:00
// Flush flushes a single key to backing.
2022-11-13 10:03:13 -05:00
Flush(key string) error
2022-11-13 11:55:10 -05:00
// Shutdown is called to quiesce and shutdown the store.
2022-11-13 10:03:13 -05:00
Shutdown()
}