diff --git a/README.md b/README.md index d893e65..cfb736a 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/ledis/binlog.go b/ledis/binlog.go index d6e99f0..7ae7030 100644 --- a/ledis/binlog.go +++ b/ledis/binlog.go @@ -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) diff --git a/ledis/binlog_test.go b/ledis/binlog_test.go index 7fc89b4..c010771 100644 --- a/ledis/binlog_test.go +++ b/ledis/binlog_test.go @@ -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) } diff --git a/ledis/doc.go b/ledis/doc.go index 222ef09..f5c02f2 100644 --- a/ledis/doc.go +++ b/ledis/doc.go @@ -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). diff --git a/ledis/dump_test.go b/ledis/dump_test.go index c8bfe36..8ca80b8 100644 --- a/ledis/dump_test.go +++ b/ledis/dump_test.go @@ -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) } diff --git a/ledis/ledis.go b/ledis/ledis.go index 0d8f8a0..97011c9 100644 --- a/ledis/ledis.go +++ b/ledis/ledis.go @@ -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 } diff --git a/ledis/ledis_test.go b/ledis/ledis_test.go index dc28b5c..aba2a62 100644 --- a/ledis/ledis_test.go +++ b/ledis/ledis_test.go @@ -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) diff --git a/ledis/replication_test.go b/ledis/replication_test.go index 7e9aa20..bc33f78 100644 --- a/ledis/replication_test.go +++ b/ledis/replication_test.go @@ -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" } diff --git a/leveldb/db.go b/leveldb/db.go index 52c330c..ed61b18 100644 --- a/leveldb/db.go +++ b/leveldb/db.go @@ -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 } diff --git a/leveldb/leveldb_test.go b/leveldb/leveldb_test.go index 7289ed9..5da84d4 100644 --- a/leveldb/leveldb_test.go +++ b/leveldb/leveldb_test.go @@ -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) } diff --git a/server/app.go b/server/app.go index 5a9bb87..9f155c1 100644 --- a/server/app.go +++ b/server/app.go @@ -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 }