adjust Open interface, not backwards compatibility

This commit is contained in:
siddontang 2014-07-04 15:45:23 +08:00
parent 38f741ddb1
commit 6adfb1be98
11 changed files with 23 additions and 23 deletions

View File

@ -44,7 +44,7 @@ Ledisdb is a high performance nosql like redis based on leveldb written by go. I
## Lib
import "github.com/siddontang/ledisdb/ledis"
l, _ := ledis.OpenWithConfig(cfg)
l, _ := ledis.Open(cfg)
db, _ := l.Select(0)
db.Set(key, value)

View File

@ -66,17 +66,17 @@ type BinLog struct {
lastLogIndex int64
}
func NewBinLog(data json.RawMessage) (*BinLog, error) {
func NewBinLogWithJsonConfig(data json.RawMessage) (*BinLog, error) {
var cfg BinLogConfig
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, err
}
return NewBinLogWithConfig(&cfg)
return NewBinLog(&cfg)
}
func NewBinLogWithConfig(cfg *BinLogConfig) (*BinLog, error) {
func NewBinLog(cfg *BinLogConfig) (*BinLog, error) {
cfg.adjust()
l := new(BinLog)

View File

@ -15,7 +15,7 @@ func TestBinLog(t *testing.T) {
os.RemoveAll(cfg.Path)
b, err := NewBinLogWithConfig(cfg)
b, err := NewBinLog(cfg)
if err != nil {
t.Fatal(err)
}

View File

@ -7,7 +7,7 @@
//
// First create a ledis instance before use:
//
// l := ledis.OpenWithConfig(cfg)
// l := ledis.Open(cfg)
//
// cfg is a Config instance which contains configuration for ledis use,
// like DataDir (root directory for ledis working to store data).

View File

@ -23,7 +23,7 @@ func TestDump(t *testing.T) {
}
`)
master, err := Open(masterConfig)
master, err := OpenWithJsonConfig(masterConfig)
if err != nil {
t.Fatal(err)
}
@ -41,7 +41,7 @@ func TestDump(t *testing.T) {
`)
var slave *Ledis
if slave, err = Open(slaveConfig); err != nil {
if slave, err = OpenWithJsonConfig(slaveConfig); err != nil {
t.Fatal(err)
}

View File

@ -50,17 +50,17 @@ type Ledis struct {
jobs *sync.WaitGroup
}
func Open(configJson json.RawMessage) (*Ledis, error) {
func OpenWithJsonConfig(configJson json.RawMessage) (*Ledis, error) {
var cfg Config
if err := json.Unmarshal(configJson, &cfg); err != nil {
return nil, err
}
return OpenWithConfig(&cfg)
return Open(&cfg)
}
func OpenWithConfig(cfg *Config) (*Ledis, error) {
func Open(cfg *Config) (*Ledis, error) {
if len(cfg.DataDir) == 0 {
return nil, fmt.Errorf("must set correct data_dir")
}
@ -69,7 +69,7 @@ func OpenWithConfig(cfg *Config) (*Ledis, error) {
cfg.DataDB.Path = path.Join(cfg.DataDir, "data")
}
ldb, err := leveldb.OpenWithConfig(&cfg.DataDB)
ldb, err := leveldb.Open(&cfg.DataDB)
if err != nil {
return nil, err
}
@ -85,7 +85,7 @@ func OpenWithConfig(cfg *Config) (*Ledis, error) {
if len(cfg.BinLog.Path) == 0 {
cfg.BinLog.Path = path.Join(cfg.DataDir, "bin_log")
}
l.binlog, err = NewBinLogWithConfig(&cfg.BinLog)
l.binlog, err = NewBinLog(&cfg.BinLog)
if err != nil {
return nil, err
}

View File

@ -31,7 +31,7 @@ func getTestDB() *DB {
os.RemoveAll("/tmp/test_ledis")
var err error
testLedis, err = Open(d)
testLedis, err = OpenWithJsonConfig(d)
if err != nil {
println(err.Error())
panic(err)

View File

@ -32,7 +32,7 @@ func TestReplication(t *testing.T) {
os.RemoveAll("/tmp/test_repl")
master, err = Open([]byte(`
master, err = OpenWithJsonConfig([]byte(`
{
"data_dir" : "/tmp/test_repl/master",
"use_bin_log" : true,
@ -45,7 +45,7 @@ func TestReplication(t *testing.T) {
t.Fatal(err)
}
slave, err = Open([]byte(`
slave, err = OpenWithJsonConfig([]byte(`
{
"data_dir" : "/tmp/test_repl/slave"
}

View File

@ -1,4 +1,4 @@
//a wrapper for c++ leveldb
//a wrapper for c++ leveldb
package leveldb
/*
@ -44,17 +44,17 @@ type DB struct {
filter *FilterPolicy
}
func Open(configJson json.RawMessage) (*DB, error) {
func OpenWithJsonConfig(configJson json.RawMessage) (*DB, error) {
cfg := new(Config)
err := json.Unmarshal(configJson, cfg)
if err != nil {
return nil, err
}
return OpenWithConfig(cfg)
return Open(cfg)
}
func OpenWithConfig(cfg *Config) (*DB, error) {
func Open(cfg *Config) (*DB, error) {
if err := os.MkdirAll(cfg.Path, os.ModePerm); err != nil {
return nil, err
}

View File

@ -24,7 +24,7 @@ var testDB *DB
func getTestDB() *DB {
f := func() {
var err error
testDB, err = Open(testConfigJson)
testDB, err = OpenWithJsonConfig(testConfigJson)
if err != nil {
println(err.Error())
panic(err)
@ -247,7 +247,7 @@ func TestCloseMore(t *testing.T) {
cfg.CacheSize = 4 * 1024 * 1024
os.RemoveAll(cfg.Path)
for i := 0; i < 100; i++ {
db, err := OpenWithConfig(cfg)
db, err := Open(cfg)
if err != nil {
t.Fatal(err)
}

View File

@ -66,7 +66,7 @@ func NewApp(cfg *Config) (*App, error) {
}
}
if app.ldb, err = ledis.OpenWithConfig(&cfg.DB); err != nil {
if app.ldb, err = ledis.Open(&cfg.DB); err != nil {
return nil, err
}