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