Renames and Preallocations
This commit is contained in:
parent
7e12d11ea9
commit
cbcbf42f5b
|
@ -105,7 +105,7 @@ const (
|
|||
// In the case of an error, withAll will continue and return a compound form of any errors that occurred.
|
||||
// For now this is just for Close and Sync, thusly it does a hard lock on the Keeper.
|
||||
func (db *DB) withAll(action withAllAction) error {
|
||||
var errs []error
|
||||
var errs = make([]error, len(db.store))
|
||||
if len(db.store) < 1 {
|
||||
return errNoStores
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ func (db *DB) withAll(action withAllAction) error {
|
|||
|
||||
// SyncAndCloseAll implements the method from Keeper.
|
||||
func (db *DB) SyncAndCloseAll() error {
|
||||
var errs []error
|
||||
var errs = make([]error, len(db.store))
|
||||
errSync := namedErr("sync", db.SyncAll())
|
||||
if errSync != nil {
|
||||
errs = append(errs, errSync)
|
||||
|
|
|
@ -43,7 +43,6 @@ func TestDB_Init(t *testing.T) {
|
|||
}
|
||||
type test struct {
|
||||
name string
|
||||
fields *DB
|
||||
args args
|
||||
wantErr bool
|
||||
specErr error
|
||||
|
@ -52,20 +51,17 @@ func TestDB_Init(t *testing.T) {
|
|||
tests := []test{
|
||||
{
|
||||
name: "simple",
|
||||
fields: db,
|
||||
args: args{"simple"},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "storeExists",
|
||||
fields: db,
|
||||
args: args{"simple"},
|
||||
wantErr: true,
|
||||
specErr: errStoreExists,
|
||||
},
|
||||
{
|
||||
name: "newStore",
|
||||
fields: db,
|
||||
args: args{"notsimple"},
|
||||
wantErr: false,
|
||||
},
|
||||
|
|
|
@ -16,7 +16,6 @@ type KeyValue struct {
|
|||
type Key struct {
|
||||
database.Key
|
||||
b []byte
|
||||
s string
|
||||
}
|
||||
|
||||
// Bytes returns the raw byte slice form of the Key.
|
||||
|
@ -38,7 +37,6 @@ func (k Key) Equal(k2 Key) bool {
|
|||
type Value struct {
|
||||
database.Value
|
||||
b []byte
|
||||
s string
|
||||
}
|
||||
|
||||
// Bytes returns the raw byte slice form of the Value.
|
||||
|
|
14
keeper.go
14
keeper.go
|
@ -5,14 +5,14 @@ package database
|
|||
type Keeper interface {
|
||||
// Path should return the base path where all stores should be stored under. (likely as subdirectories)
|
||||
Path() string
|
||||
// Init should initialize our Filer at the given path, to be referenced and called by storeName.
|
||||
Init(storeName string) error
|
||||
// With provides access to the given storeName by providing a pointer to the related Filer.
|
||||
With(storeName string) Filer
|
||||
// Close should safely end any Filer operations of the given storeName and close any relevant handlers.
|
||||
Close(storeName string) error
|
||||
// Init should initialize our Filer at the given path, to be referenced and called by dataStore.
|
||||
Init(dataStore []byte) error
|
||||
// With provides access to the given dataStore by providing a pointer to the related Filer.
|
||||
With(dataStore []byte) Filer
|
||||
// Close should safely end any Filer operations of the given dataStore and close any relevant handlers.
|
||||
Close(dataStore []byte) error
|
||||
// Sync should take any volatile data and solidify it somehow if relevant. (ram to disk in most cases)
|
||||
Sync(storeName string) error
|
||||
Sync(dataStore []byte) error
|
||||
|
||||
// TODO: Backups
|
||||
|
||||
|
|
Loading…
Reference in New Issue