Remove logger dependency

This commit is contained in:
rednexela1941 2020-11-13 23:41:16 -05:00
parent 9cb3ddeded
commit c0df5fa97b
4 changed files with 15 additions and 22 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/sdomino/scribble"
)
@ -15,7 +16,7 @@ func main() {
db, err := scribble.New(dir, nil)
if err != nil {
fmt.Println("Error", err)
fmt.Println("Error", err.Error())
}
// Write a fish to the database
@ -26,13 +27,13 @@ func main() {
// Read a fish from the database (passing fish by reference)
onefish := Fish{}
if err := db.Read("fish", "onefish", &onefish); err != nil {
fmt.Println("Error", err)
fmt.Println("Error", err.Error())
}
// Read all fish from the database, unmarshaling the response.
records, err := db.ReadAll("fish")
if err != nil {
fmt.Println("Error", err)
fmt.Println("Error", err.Error())
}
fishies := []Fish{}

2
go.mod
View File

@ -1,3 +1,5 @@
module github.com/sdomino/scribble
go 1.15
require github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25 h1:EFT6MH3igZK/dIVqgGbTqWVvkZ7wJ5iGN03SVtvvdd8=
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25/go.mod h1:sWkGw/wsaHtRsT9zGQ/WyJCotGWG/Anow/9hsAcBWRw=

View File

@ -6,11 +6,10 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"sync"
"github.com/jcelliott/lumber"
)
// Version is the current version of the project
@ -22,29 +21,19 @@ var (
)
type (
// Logger is a generic logger interface
Logger interface {
Fatal(string, ...interface{})
Error(string, ...interface{})
Warn(string, ...interface{})
Info(string, ...interface{})
Debug(string, ...interface{})
Trace(string, ...interface{})
}
// Driver is what is used to interact with the scribble database. It runs
// transactions, and provides log output
Driver struct {
mutex sync.Mutex
mutexes map[string]*sync.Mutex
dir string // the directory where scribble will create the database
log Logger // the logger scribble will log to
dir string // the directory where scribble will create the database
log *log.Logger // the logger scribble will log to
}
)
// Options uses for specification of working golang-scribble
type Options struct {
Logger // the logger scribble will use (configurable)
Logger *log.Logger // the logger scribble will use (configurable)
}
// New creates a new scribble database at the desired directory location, and
@ -64,7 +53,7 @@ func New(dir string, options *Options) (*Driver, error) {
// if no logger is provided, create a default
if opts.Logger == nil {
opts.Logger = lumber.NewConsoleLogger(lumber.INFO)
opts.Logger = log.New(os.Stdout, "scribble> ", log.LstdFlags)
}
//
@ -76,12 +65,12 @@ func New(dir string, options *Options) (*Driver, error) {
// if the database already exists, just use it
if _, err := os.Stat(dir); err == nil {
opts.Logger.Debug("Using '%s' (database already exists)\n", dir)
opts.Logger.Printf("Using '%s' (database already exists)\n", dir)
return &driver, nil
}
// if the database doesn't exist create it
opts.Logger.Debug("Creating scribble database at '%s'...\n", dir)
opts.Logger.Printf("Creating database at '%s'...\n", dir)
return &driver, os.MkdirAll(dir, 0755)
}
@ -238,7 +227,6 @@ func (d *Driver) Delete(collection, resource string) error {
return nil
}
//
func stat(path string) (fi os.FileInfo, err error) {
// check for dir, if path isn't a directory check to see if it's a file