removing hatchet
This commit is contained in:
parent
b14eeebb76
commit
cfe94ca72c
34
scribble.go
34
scribble.go
|
@ -11,57 +11,61 @@ package scribble
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/jcelliott/lumber"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/nanobox-io/golang-hatchet"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const Version = "1.0.1"
|
const Version = "1.0.2"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
||||||
|
//
|
||||||
|
Logger interface {
|
||||||
|
Fatal(string, ...interface{})
|
||||||
|
Error(string, ...interface{})
|
||||||
|
Warn(string, ...interface{})
|
||||||
|
Info(string, ...interface{})
|
||||||
|
Debug(string, ...interface{})
|
||||||
|
Trace(string, ...interface{})
|
||||||
|
}
|
||||||
|
|
||||||
// a Driver is what is used to interact with the scribble database. It runs
|
// a Driver is what is used to interact with the scribble database. It runs
|
||||||
// transactions, and provides log output
|
// transactions, and provides log output
|
||||||
Driver struct {
|
Driver struct {
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
mutexes map[string]sync.Mutex
|
mutexes map[string]sync.Mutex
|
||||||
dir string // the directory where scribble will create the database
|
dir string // the directory where scribble will create the database
|
||||||
log hatchet.Logger // the logger scribble will log to
|
log Logger // the logger scribble will log to
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates a new scribble database at the desired directory location, and
|
// New creates a new scribble database at the desired directory location, and
|
||||||
// returns a *Driver to then use for interacting with the database
|
// returns a *Driver to then use for interacting with the database
|
||||||
func New(dir string, logger hatchet.Logger) (*Driver, error) {
|
func New(dir string, logger Logger) (driver *Driver, err error) {
|
||||||
|
|
||||||
//
|
//
|
||||||
dir = filepath.Clean(dir)
|
dir = filepath.Clean(dir)
|
||||||
|
|
||||||
//
|
//
|
||||||
if logger == nil {
|
if logger == nil {
|
||||||
logger = hatchet.DevNullLogger{}
|
logger = lumber.NewConsoleLogger(lumber.INFO)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("Creating database directory at '%v'...\n", dir)
|
logger.Info("Creating scribble database at '%v'...\n", dir)
|
||||||
|
|
||||||
//
|
//
|
||||||
d := &Driver{
|
driver = &Driver{
|
||||||
dir: dir,
|
dir: dir,
|
||||||
mutexes: make(map[string]sync.Mutex),
|
mutexes: make(map[string]sync.Mutex),
|
||||||
log: logger,
|
log: logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
// create database
|
// create database
|
||||||
if err := mkDir(d.dir); err != nil {
|
return driver, mkDir(dir)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return d, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a record from the database
|
// Read a record from the database
|
||||||
|
|
Loading…
Reference in New Issue